also looking at this
Deploy: uniform auth session model (main → production)
#7
282 files
+3028
-64856
| @@ -8,10 +8,12 @@ | ||
| 8 | 8 | * This exists instead of the `auth` middleware alias because that alias does not |
| 9 | 9 | * reliably populate `request.user()` on these route handlers (see the note in |
| 10 | 10 | * routes/projects.ts), so the token is read and resolved directly. Two carriers |
| 11 | * are accepted: a bearer header, which is what the API clients send, and the | |
| 12 | * `loghq_token` cookie, which is what the dashboard has after signing in. | |
| 11 | * are accepted: a bearer header, which is what the external API clients send, | |
| 12 | * and the HttpOnly `auth-token` cookie (config.auth.defaultTokenName), which is | |
| 13 | * what the dashboard has after signing in. | |
| 13 | 14 | */ |
| 14 | 15 | import { Auth } from '@stacksjs/auth' |
| 16 | import { config } from '@stacksjs/config' | |
| 15 | 17 | |
| 16 | 18 | export async function userFromRequest(request: any): Promise<any | null> { |
| 17 | 19 | const authHeader = request.headers?.get?.('authorization') ?? '' |
| @@ -19,7 +21,8 @@ export async function userFromRequest(request: any): Promise<any | null> { | ||
| 19 | 21 | |
| 20 | 22 | if (!token) { |
| 21 | 23 | const cookie = request.headers?.get?.('cookie') ?? '' |
| 22 | const m = cookie.match(/(?:^|;)\s*loghq_token=([^;]+)/) | |
| 24 | const name = (config.auth?.defaultTokenName || 'auth-token').replace(/[.*+?^${}()|[\]\\]/g, '\\$&') | |
| 25 | const m = cookie.match(new RegExp(`(?:^|;)\\s*${name}=([^;]+)`)) | |
| 23 | 26 | if (m) |
| 24 | 27 | token = decodeURIComponent(m[1]) |
| 25 | 28 | } |