@luckystack/login
v0.16.1
Published
Authentication for LuckyStack: credentials + OAuth (Google/GitHub/Facebook/Discord/Microsoft/custom), Redis-backed sessions, single-session enforcement, password reset, 2FA, lifecycle hooks, and pluggable user/session adapters. Pairs with @luckystack/core
Downloads
1,647
Maintainers
Readme
@luckystack/login
Authentication and session lifecycle for LuckyStack, with credential, OAuth and adapter-backed identity options. Install with npm install @luckystack/login socket.io; add optional @prisma/client for the default user adapter and @luckystack/email for framework-managed email flows. Register user/session adapters before handling logins. Consult package.json, src/register.ts and src/userAdapter.ts for integration requirements.
Before switching an existing app to unified provider accounts: reconcile duplicate emails and dependent rows; enforce email uniqueness in the database (application checks cannot close the registration race); ensure a custom user adapter implements cross-provider email lookup; then enable the strategy. Changing cookie policy requires a CSRF/origin review. OAuth redirects must pass trusted-origin validation. Password-reset responses must not reveal whether an account exists; never expose tokens or hashes in sessions. See design context, session safety, redirect trust and account strategy.
Existing-project OAuth account binding (0.16)
- Add a nullable
providerAccountIdto the user store with an index on (provider,providerAccountId); for the default Prisma adapterproviderAccountId String?and@@index([provider, providerAccountId]). Keep the index non-unique where the store rejects repeated nulls in a unique index (MongoDB, including through Prisma or MikroORM); on SQL a unique index is fine, as in the drizzle starter. Review/apply the database change with authorization and regenerate the client. Until the column exists, OAuth logins with the default adapter fail; credentials logins keep working. - A custom adapter implements
findByProviderAccountIdand persistsproviderAccountIdfromcreateandupdate(src/userAdapter.ts). Without it the framework warns once and keeps email matching. - Existing accounts bind on their next login when the provider verified the email; an unbound account whose provider email is unverified (multi-tenant Microsoft) is refused. See ADR 0086.
Existing-project email-code / 2FA adoption
- Obtain feature approval before opting into
auth.emailCodeLogin: trueand/orauth.twoFactor: 'optional'. Register a real email sender for email-code login and any email fallback; console delivery is not sufficient. - Before 2FA enrollment, add persistence for
twoFactorEnabled(initially false), nullabletotpSecretand nullablerecoveryCodesto the user store. For the default Prisma adapter the fields areBoolean @default(false),String?andJson?respectively. Review/apply the database change with authorization and regenerate the client; custom adapters must support these fields insrc/userAdapter.ts. - Set a high-entropy secret
TOTP_ENCRYPTION_KEYbefore enrollment. Without it new TOTP secrets are stored unencrypted. Keep it outside Git/logs. During rotation retain previous values inTOTP_ENCRYPTION_LEGACY_KEYS(a JSON array of strings) until old records are migrated; deleting them early can lock users out. Seesrc/twoFactor.tsfor the installed keyring contract. - Run
npx luckystack update --app, review/merge UI.newsidecars without overwriting consumer edits, then verify enrollment, login, recovery and rotation in an authorized environment. Schema and real secrets remain manually owned.
