Something went wrong. Try again.
Something went wrong. Try again.
835 B · 31 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132import type { HttpContext } from '@adonisjs/core/http'import type { NextFn } from '@adonisjs/core/types/http'import type { Authenticators } from '@adonisjs/auth/types'import { AtprotoUser } from '@thisismissem/adonisjs-atproto-oauth'
/** * Auth middleware is used authenticate HTTP requests and deny * access to unauthenticated users. */export default class AuthMiddleware { /** * The URL to redirect to, when authentication fails */ redirectTo = '/login'
async handle( ctx: HttpContext, next: NextFn, options: { guards?: (keyof Authenticators)[] } = {} ) { await ctx.auth.authenticateUsing(options.guards, { loginRoute: this.redirectTo })
if (ctx.auth.user instanceof AtprotoUser) { ctx.containerResolver.bindValue(AtprotoUser, ctx.auth.user) }
return next() }}