This commit is contained in:
2025-10-30 02:54:47 -03:00
parent b0ae990c7d
commit a9433d5a57
8 changed files with 31 additions and 22 deletions

View File

@@ -1,8 +1,11 @@
import type { Route } from './+types'
import * as httpStatus from '@/lib/http-status'
import { parse } from 'cookie'
export const OK = 200
export const FOUND = 302
export const INTERNAL_SERVER_ERROR = 500
export async function loader({ request, context }: Route.LoaderArgs) {
const cookies = parse(request.headers.get('Cookie') || '')
const url = new URL(request.url)
@@ -13,7 +16,7 @@ export async function loader({ request, context }: Route.LoaderArgs) {
if (!cookies?.__session) {
return new Response(null, {
status: httpStatus.FOUND,
status: FOUND,
headers: {
Location: loginUrl.toString()
}
@@ -30,23 +33,23 @@ export async function loader({ request, context }: Route.LoaderArgs) {
redirect: 'manual'
})
if (r.status === httpStatus.FOUND) {
if (r.status === FOUND) {
return new Response(await r.text(), {
status: r.status,
headers: r.headers
})
}
console.log('Issuer response', {
console.log('Authorize response', {
json: await r.json(),
headers: r.headers,
status: r.status
})
// Deny authorization if user lacks scopes requested by client
if (r.status === httpStatus.FORBIDDEN) {
if (r.status === FOUND) {
return new Response(null, {
status: httpStatus.FOUND,
status: r.status,
headers: {
Location: new URL('/deny', url.origin).toString()
}
@@ -54,13 +57,13 @@ export async function loader({ request, context }: Route.LoaderArgs) {
}
return new Response(null, {
status: httpStatus.FOUND,
status: FOUND,
headers: {
Location: loginUrl.toString()
}
})
} catch (error) {
console.error(error)
return new Response(null, { status: httpStatus.INTERNAL_SERVER })
return new Response(null, { status: INTERNAL_SERVER_ERROR })
}
}