Compare commits
1 Commits
feature/au
...
feature/au
Author | SHA1 | Date | |
---|---|---|---|
230fcf79df
|
@@ -3,24 +3,24 @@ import { oauthProviders } from '$lib/server/oauth';
|
|||||||
import { is } from 'typia';
|
import { is } from 'typia';
|
||||||
import { type AuthProvider, enabledAuthProviders } from '$lib/auth';
|
import { type AuthProvider, enabledAuthProviders } from '$lib/auth';
|
||||||
|
|
||||||
export async function GET(event) {
|
export async function GET({ params: { provider }, url, cookies }) {
|
||||||
const { provider } = event.params;
|
|
||||||
if (!is<AuthProvider>(provider) || !enabledAuthProviders[provider]) {
|
if (!is<AuthProvider>(provider) || !enabledAuthProviders[provider]) {
|
||||||
return new Response(null, { status: 404 });
|
return new Response(null, { status: 404 });
|
||||||
}
|
}
|
||||||
const oauthProvider = oauthProviders[provider];
|
const oauthProvider = oauthProviders[provider];
|
||||||
|
|
||||||
|
const inviteToken = url.searchParams.get('invite') ?? '';
|
||||||
const state = generateState();
|
const state = generateState();
|
||||||
const codeVerifier = generateCodeVerifier();
|
const codeVerifier = generateCodeVerifier();
|
||||||
const url = oauthProvider.createAuthorizationURL(state, codeVerifier);
|
const authUrl = oauthProvider.createAuthorizationURL(state + inviteToken, codeVerifier);
|
||||||
|
|
||||||
event.cookies.set(`${provider}_oauth_state`, state, {
|
cookies.set(`${provider}_oauth_state`, state, {
|
||||||
path: '/',
|
path: '/',
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
maxAge: 60 * 10, // 10 minutes
|
maxAge: 60 * 10, // 10 minutes
|
||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
});
|
});
|
||||||
event.cookies.set(`${provider}_code_verifier`, codeVerifier, {
|
cookies.set(`${provider}_code_verifier`, codeVerifier, {
|
||||||
path: '/',
|
path: '/',
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
maxAge: 60 * 10, // 10 minutes
|
maxAge: 60 * 10, // 10 minutes
|
||||||
@@ -30,7 +30,7 @@ export async function GET(event) {
|
|||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 302,
|
status: 302,
|
||||||
headers: {
|
headers: {
|
||||||
Location: url.toString(),
|
Location: authUrl.toString(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user