Strip surrounding quotes from script args; add diag-user
When npm run create-user is invoked from Windows Git Bash with single-quoted values (--password 'foo' --name 'Berwn'), the quotes survive into process.argv and end up stored in the DB. Login fails silently because the stored hash is for 'foo' but the user types foo. create-user and diag-user now strip a single set of matching surrounding quotes from every --flag value. Real values that need literal leading and trailing quotes can be escaped. diag-user prints the full user row (email, normalized email, hash prefix, isActive, memberships, session count) and optionally verifies a password. Useful whenever a login mystery shows up. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+11
-1
@@ -6,9 +6,19 @@ import { users, companies, companyUsers } from '../src/lib/server/db/schema/tena
|
||||
import { hashPassword } from '../src/lib/server/auth/password';
|
||||
import { normalizeEmail } from '../src/lib/utils/email';
|
||||
|
||||
function stripSurroundingQuotes(s: string | undefined): string | undefined {
|
||||
if (!s || s.length < 2) return s;
|
||||
const first = s[0];
|
||||
const last = s[s.length - 1];
|
||||
if ((first === "'" && last === "'") || (first === '"' && last === '"')) {
|
||||
return s.slice(1, -1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function readArg(flag: string, fallback?: string): string | undefined {
|
||||
const i = process.argv.indexOf(flag);
|
||||
return i >= 0 ? process.argv[i + 1] : fallback;
|
||||
return stripSurroundingQuotes(i >= 0 ? process.argv[i + 1] : fallback);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
||||
Reference in New Issue
Block a user