From c467589b1bc63aca95c0f2e21b9a85d91d3c7ae2 Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 29 Mar 2024 21:34:47 +0100 Subject: [PATCH] fix: auth --- docs/src/pages/auth/authorize.js | 6 ++---- docs/src/pages/auth/authorized.js | 6 ------ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/docs/src/pages/auth/authorize.js b/docs/src/pages/auth/authorize.js index 4ab9ba1..df09861 100644 --- a/docs/src/pages/auth/authorize.js +++ b/docs/src/pages/auth/authorize.js @@ -8,13 +8,11 @@ export async function GET({url, redirect}) { const myUrl = new URL(url); const params = new URLSearchParams(myUrl.search); - const redirectUrl = params.get('redirect_uri'); + const redirect_uri = params.get('redirect_uri'); const { GITHUB_CLIENT_ID } = import.meta.env; - - const redirect_uri = 'http://localhost:4321/auth/authorized' - const state = toHexString(redirectUrl); + const state = toHexString(redirect_uri); const oauthParams = new URLSearchParams({ client_id:GITHUB_CLIENT_ID , redirect_uri, state }); return redirect(`${GITHUB_OAUTH_AUTHORIZE_URL}?${oauthParams}`, 302) diff --git a/docs/src/pages/auth/authorized.js b/docs/src/pages/auth/authorized.js index 22e2869..f9a8122 100644 --- a/docs/src/pages/auth/authorized.js +++ b/docs/src/pages/auth/authorized.js @@ -3,7 +3,6 @@ import { fromHexString } from '../../utils/encrypt'; export const prerender = false; const GITHUB_OAUTH_ACCESS_TOKEN_URL = 'https://github.com/login/oauth/access_token'; -const TOKEN_VALIDITY_PERIOD = 1000 * 60 * 60 * 24 * 365; // 1 year; export async function GET({ url, redirect, cookies}) { @@ -17,8 +16,6 @@ export async function GET({ url, redirect, cookies}) { const redirectUrl = new URL(fromHexString(state)); - console.log('Authorized', GITHUB_CLIENT_ID); - if (error && error === 'access_denied') { redirect(redirectUrl.href, 302); return; @@ -51,14 +48,11 @@ export async function GET({ url, redirect, cookies}) { status: 503 } ) - return; } - // cookies.set('token', accessToken, { expires: new Date(Date.now() + TOKEN_VALIDITY_PERIOD), secure: true, httpOnly: true, path: '/' }); cookies.set('refresh', refreshToken, { secure: true, httpOnly: true, path: '/' }); redirectUrl.searchParams.set('token', accessToken); - // redirectUrl.searchParams.set('refresh', refreshToken); return redirect(redirectUrl.href, 302); }