Junction guide / Identity
Auth
Junction defines an IAuth interface and ships no vendor adapter; @frontierjs/auth is the native one. Mounting it gives the app /auth/* routes and a session that arrives as ctx.user.
const signedOut = await client.auth.me().catch(() => null)
if (signedOut) throw new Error('an anonymous caller has no account')
await client.auth.signUp({ email: 'alice@example.com', password: 'correct horse battery', name: 'Alice' })
const { token } = await client.auth.signIn('alice@example.com', 'correct horse battery')
if (!token) throw new Error('sign-in returned no token')
const me = await client.auth.me() as any
if (me.email !== 'alice@example.com') throw new Error('the token did not identify Alice')
What else it can do
fli auth:installappendsUsertodb/schema.liteand importsCredential,Sessionand the other models the package bringsapp.configure(authPlugin({ auth }))mounts/auth/*for anauthmade withcreateLitestoneAuth(db);createApp({ auth, db })is the other half- The transport reads
Authorization: BearerorX-API-Key, asksauth.verifySession()and stampsctx.user - The
authenticatehook refuses a call that has noctx.user - A browser holding a session cookie is signed in by cookie mode; a request that is not a bearer token has its own credential verifier
client.authalso holdssignOut,sessions,revokeOtherSessions,createApiKey,changePassword,reauthenticate,requestPasswordResetand the magic-link pair- Routes establish a session and services change one's own credentials afterward, so those get hooks and the audit trail
- The mailed flows need your mailer:
onPasswordResetRequested,onEmailVerificationRequestedandonMagicLinkRequestedreceive the token to send; settingonMagicLinkRequestedis what turns the passwordless routes on onCredentialChangedhears every change to how an account signs in, so the person who did not make it can be told- A
totpcredential makes sign-in answer a challenge ticket instead of a token, finished byclient.auth.completeSignIn(code);requireSecondFactorasks it of every account or the ones a function names - Changing a credential asks for a recent password: past
reauthenticationWindowa call answers 403reauthentication_requireduntilreauthenticateruns - An operator acts as another account with
/auth/support/start, which needscanStartSupportand records the episode under the operator IAuth.requestPasswordReset,requestEmailVerificationandrequestMagicLinkare optional; an adapter that omits them handles those routes itself- A different auth library implements
IAuthand mounts its handler on a raw route SessionContextis whatctx.userlooks like:id,userType,authMethod,email,role,scopes, tenant ids and the standing fields the gate reads
In depth: README § Auth and packages/auth/README.md