also looking at this
Deploy: uniform auth session model (main → production)
#7
282 files
+3028
-64856
| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | import type { RequestInstance } from '@stacksjs/types' |
| 2 | 2 | import { Action } from '@stacksjs/actions' |
| 3 | import { Auth } from '@stacksjs/auth' | |
| 4 | 3 | import { db } from '@stacksjs/database' |
| 5 | 4 | import { Payment } from '@stacksjs/payments' |
| 6 | 5 | import { response } from '@stacksjs/router' |
| 6 | import { userFromRequest } from '../Support/request-auth' | |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Return the authenticated user plus their Pro status. The dashboard calls this |
| @@ -16,9 +16,10 @@ export default new Action({ | ||
| 16 | 16 | description: 'Return the current user and their Pro status', |
| 17 | 17 | method: 'GET', |
| 18 | 18 | async handle(request: RequestInstance) { |
| 19 | const authHeader = ((request as any).headers?.get?.('authorization') ?? '') | |
| 20 | const bearer = (request as any).bearerToken?.() ?? authHeader.replace(/^Bearer\s+/i, '') | |
| 21 | const user = bearer ? await Auth.getUserFromToken(bearer) : await request.user() | |
| 19 | // Resolve from either carrier: an external bearer header, or the HttpOnly | |
| 20 | // `auth-token` cookie the dashboard sends on same-origin fetches. /api/me | |
| 21 | // has no `.middleware('auth')`, so the resolution happens here. | |
| 22 | const user = await userFromRequest(request) | |
| 22 | 23 | if (!user) |
| 23 | 24 | return response.unauthorized('Authentication required') |
| 24 | 25 | |