MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / requireAuth

Function requireAuth

apps/api/src/api/auth/auth.plugin.ts:154–173  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

152 * `/refresh`, `/mfa/status`), reach for `tryAuth` instead.
153 */
154export const requireAuth = () =>
155 new Elysia()
156 .use(createJWTConfig())
157 .derive(
158 async ({
159 jwt: jwtPlugin,
160 cookie,
161 }): Promise<{ user: IUser; accountId: string }> => {
162 const session = await verifyAuthCookie(
163 jwtPlugin,
164 cookie[AUTH_COOKIE_NAME]?.value
165 );
166
167 if (session === null) {
168 throw ApiErrors.unauthorized("Missing authentication cookie");
169 }
170
171 return session;
172 }
173 );
174
175/**
176 * Best-effort auth guard. Resolves the session if one is presented and

Callers 12

requirePlatformAdminFunction · 0.90
users.routes.tsFile · 0.90
mfa.routes.tsFile · 0.90
auth.routes.tsFile · 0.90
accounts.routes.tsFile · 0.90
billing.routes.tsFile · 0.90
buildProbeAppFunction · 0.90
buildFreshProbeAppFunction · 0.90

Calls 2

createJWTConfigFunction · 0.90
verifyAuthCookieFunction · 0.85

Tested by 2

buildProbeAppFunction · 0.72
buildFreshProbeAppFunction · 0.72