fix redirect
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import type { Route } from './+types'
|
import type { Route } from './+types'
|
||||||
|
|
||||||
|
import { redirect } from 'react-router'
|
||||||
import { parse } from 'cookie'
|
import { parse } from 'cookie'
|
||||||
|
|
||||||
export async function loader({ request, context }: Route.LoaderArgs) {
|
export async function loader({ request, context }: Route.LoaderArgs) {
|
||||||
@@ -19,7 +20,6 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
const r = await fetch(issuerUrl.toString(), {
|
const r = await fetch(issuerUrl.toString(), {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: new Headers([
|
headers: new Headers([
|
||||||
@@ -36,20 +36,9 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Authorize response', {
|
|
||||||
json: await r.json(),
|
|
||||||
headers: r.headers,
|
|
||||||
status: r.status
|
|
||||||
})
|
|
||||||
|
|
||||||
// Deny authorization if user lacks scopes requested by client
|
// Deny authorization if user lacks scopes requested by client
|
||||||
if (r.status === 302) {
|
if (r.status === 403) {
|
||||||
return new Response(null, {
|
throw redirect(new URL('/deny', url.origin).toString())
|
||||||
status: r.status,
|
|
||||||
headers: {
|
|
||||||
Location: new URL('/deny', url.origin).toString()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
@@ -58,8 +47,4 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
|||||||
Location: loginUrl.toString()
|
Location: loginUrl.toString()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
return new Response(null, { status: 500 })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user