From beb24b342b1fb80cee26ebc1ed5b9eca892b2bae Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 20 May 2024 22:08:21 +0200 Subject: [PATCH] fix: make oauth work again --- .../src/components/widgets/CallToAction.astro | 2 +- front/src/pages/account/login.astro | 46 +++++++++++++++++-- front/src/pages/account/oauth.astro | 13 ++++-- front/src/pages/account/register.astro | 10 ++-- 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/front/src/components/widgets/CallToAction.astro b/front/src/components/widgets/CallToAction.astro index 83aac1e..be1a34e 100644 --- a/front/src/components/widgets/CallToAction.astro +++ b/front/src/components/widgets/CallToAction.astro @@ -45,7 +45,7 @@ const { {Array.isArray(actions) ? ( actions.map((action) => (
-
)) ) : ( diff --git a/front/src/pages/account/login.astro b/front/src/pages/account/login.astro index 7ef7cca..c87330d 100644 --- a/front/src/pages/account/login.astro +++ b/front/src/pages/account/login.astro @@ -4,8 +4,7 @@ import Layout from 'layouts/PageLayout.astro'; import AstroUtils from "libs/AstroUtils"; import PocketBase from 'pocketbase' import ContactUs from 'components/widgets/Contact.astro'; -import FormContainer from 'components/ui/Form.astro'; - +import CallToAction from 'components/widgets/CallToAction.astro'; const pb = Astro.locals.pb @@ -13,7 +12,9 @@ if(pb.authStore.isValid){ return Astro.redirect("/account") } -console.log(Astro.request.method); +const oauths = (await pb.collection('users').listAuthMethods()).authProviders; +const discordProvider = oauths.find(item => item.name === 'discord'); +const googleProvider = oauths.find(item => item.name === 'google'); await AstroUtils.wrap(async () => { @@ -45,8 +46,8 @@ const metadata = { + + + Oauth + + + + Connecter Vous aussi avec + + + + diff --git a/front/src/pages/account/oauth.astro b/front/src/pages/account/oauth.astro index 837b6cc..6ab0b4a 100644 --- a/front/src/pages/account/oauth.astro +++ b/front/src/pages/account/oauth.astro @@ -24,9 +24,13 @@ if (!code) { // compare the redirect's state param and the stored provider's one if (provider.state !== params.get('state')) { + console.log(provider.state) + console.log(params.get('state')) throw "State parameters don't match."; } +let authenticated = false + await pb.collection('users').authWithOAuth2Code( provider.name, code, @@ -41,12 +45,15 @@ await pb.collection('users').authWithOAuth2Code( console.log(JSON.stringify(authData, null, 2)); console.log(pb.authStore.isValid); console.log(pb.authStore.isValid); - return Astro.redirect("/account") -}).catch((err) => { + authenticated = true + }).catch((err) => { console.log("oauth fail !!"); console.log(err); -}); + }); +if (authenticated) { + return Astro.redirect("/account") +} --- diff --git a/front/src/pages/account/register.astro b/front/src/pages/account/register.astro index 39552b4..78f884e 100644 --- a/front/src/pages/account/register.astro +++ b/front/src/pages/account/register.astro @@ -8,7 +8,13 @@ import Form from 'components/ui/Form.astro'; const pb = Astro.locals.pb +if(pb.authStore.isValid){ + return Astro.redirect("/account") +} + const oauths = await pb.collection('users').listAuthMethods(); +const discordProvider = oauths.authProviders.find(item => item.name === 'discord'); +const googleProvider = oauths.authProviders.find(item => item.name === 'google'); console.log(JSON.stringify(oauths.authProviders[0])); @@ -21,14 +27,12 @@ if (getEnv('NODE_ENV', 'production') !== 'production') { Astro.cookies.set('provider', oauths.authProviders[0],{ httpOnly: true, path: '/', + secure: secure, sameSite: 'lax', maxAge: 365000 }) -if(pb.authStore.isValid){ - return Astro.redirect("/account") -} await AstroUtils.wrap(async () => { if (Astro.request.method !== 'POST'){