mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: login without cookies auth issues fix
This commit is contained in:
parent
d6d8b58358
commit
c0598bf5b4
1 changed files with 19 additions and 7 deletions
|
|
@ -42,14 +42,25 @@ export default async function middleware(req: NextRequest) {
|
||||||
// Redirect to the same pathname with the original search params
|
// Redirect to the same pathname with the original search params
|
||||||
return NextResponse.rewrite(new URL(`${pathname}${search}`, req.url))
|
return NextResponse.rewrite(new URL(`${pathname}${search}`, req.url))
|
||||||
}
|
}
|
||||||
if (auth_paths.includes(pathname)) {
|
|
||||||
// Redirect to the same pathname with the original search params
|
|
||||||
return NextResponse.rewrite(new URL(`/auth${pathname}${search}`, req.url))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Login
|
if (auth_paths.includes(pathname)) {
|
||||||
if (orgslug == 'auth' || pathname.startsWith('/login')) {
|
const response = NextResponse.rewrite(
|
||||||
return NextResponse.rewrite(new URL(`/login${search}`, req.url))
|
new URL(`/auth${pathname}${search}`, req.url)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Parse the search params
|
||||||
|
const searchParams = new URLSearchParams(search)
|
||||||
|
const orgslug = searchParams.get('orgslug')
|
||||||
|
|
||||||
|
if (orgslug) {
|
||||||
|
response.cookies.set({
|
||||||
|
name: 'learnhouse_current_orgslug',
|
||||||
|
value: orgslug,
|
||||||
|
domain:
|
||||||
|
LEARNHOUSE_TOP_DOMAIN == 'localhost' ? '' : LEARNHOUSE_TOP_DOMAIN,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install Page (depreceated)
|
// Install Page (depreceated)
|
||||||
|
|
@ -84,6 +95,7 @@ export default async function middleware(req: NextRequest) {
|
||||||
}
|
}
|
||||||
return NextResponse.redirect(redirectUrl)
|
return NextResponse.redirect(redirectUrl)
|
||||||
} else {
|
} else {
|
||||||
|
return 'Did not find the orgslug in the cookie'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue