ReviewOS

also looking at this

loghqorg/loghq

Deploy: uniform auth session model (main → production)

#7
Merged glennmichael123 wants to merge main into production
282 files +3028 -64856
app/Support/request-auth.tsmodified+6-3
Changes to app/Support/request-auth.ts
@@ -8,10 +8,12 @@
88 * This exists instead of the `auth` middleware alias because that alias does not
99 * reliably populate `request.user()` on these route handlers (see the note in
1010 * 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.
1314 */
1415import { Auth } from '@stacksjs/auth'
16import { config } from '@stacksjs/config'
1517
1618export async function userFromRequest(request: any): Promise<any | null> {
1719 const authHeader = request.headers?.get?.('authorization') ?? ''
@@ -19,7 +21,8 @@ export async function userFromRequest(request: any): Promise<any | null> {
1921
2022 if (!token) {
2123 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}=([^;]+)`))
2326 if (m)
2427 token = decodeURIComponent(m[1])
2528 }