fix: improve auth handling and logging
This commit is contained in:
8
auth.ts
8
auth.ts
@@ -136,7 +136,9 @@ export const config = {
|
||||
return session
|
||||
},
|
||||
async redirect({ baseUrl, url }) {
|
||||
console.log(`[auth] deciding redirect URL`, { baseUrl, url })
|
||||
if (url.startsWith("/")) {
|
||||
console.log(`[auth] relative URL accepted, returning: ${baseUrl}${url}`)
|
||||
// Allows relative callback URLs
|
||||
return `${baseUrl}${url}`
|
||||
} else {
|
||||
@@ -146,17 +148,19 @@ export const config = {
|
||||
if (
|
||||
/\.scandichotels\.(dk|de|com|fi|no|se)$/.test(parsedUrl.hostname)
|
||||
) {
|
||||
console.log(`[auth] subdomain URL accepted, returning: ${url}`)
|
||||
// Allows any subdomains on all top level domains above
|
||||
return url
|
||||
} else if (parsedUrl.origin === baseUrl) {
|
||||
// Allows callback URLs on the same origin
|
||||
console.log(`[auth] origin URL accepted, returning: ${url}`)
|
||||
return url
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error in auth redirect callback")
|
||||
console.error(e)
|
||||
console.error(`[auth] error parsing incoming URL for redirection`, e)
|
||||
}
|
||||
}
|
||||
console.log(`[auth] URL denied, returning base URL: ${baseUrl}`)
|
||||
return baseUrl
|
||||
},
|
||||
async authorized({ auth, request }) {
|
||||
|
||||
Reference in New Issue
Block a user