add astro template for front #13
@ -45,7 +45,7 @@ const {
|
||||
{Array.isArray(actions) ? (
|
||||
actions.map((action) => (
|
||||
<div class="flex w-full sm:w-auto">
|
||||
<Button {...(action || {})} class="w-full sm:mb-0" />
|
||||
<Button {...(action || {})} class:list={["w-full", "sm:mb-0", action.class]} />
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
|
@ -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 = {
|
||||
<Layout metadata={metadata}>
|
||||
<ContactUs
|
||||
formid="account-creation"
|
||||
title="Inscription"
|
||||
subtitle="Incrivez-vous pour sauvegardez vos recherche"
|
||||
title="Connexion"
|
||||
subtitle="Connecter pour sauvegardez vos recherche"
|
||||
button='Connexion'
|
||||
method='post'
|
||||
enctype="multipart/form-data"
|
||||
@ -63,4 +64,39 @@ const metadata = {
|
||||
}
|
||||
]}
|
||||
/>
|
||||
<CallToAction
|
||||
actions={[
|
||||
{
|
||||
variant: 'primary',
|
||||
text: 'Discord',
|
||||
href: discordProvider!.authUrl + Astro.url.protocol + "//" + Astro.url.host + '/account/oauth',
|
||||
icon: 'tabler:brand-discord',
|
||||
class: "oauth-btn",
|
||||
"data-cookie": encodeURIComponent(JSON.stringify(discordProvider))
|
||||
},
|
||||
{
|
||||
variant: 'primary',
|
||||
text: 'Google',
|
||||
href: googleProvider!.authUrl + Astro.url.protocol + "//" + Astro.url.host + '/account/oauth',
|
||||
icon: 'tabler:brand-google',
|
||||
class: "oauth-btn",
|
||||
"data-cookie": encodeURIComponent(JSON.stringify(googleProvider))
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Fragment slot="title">
|
||||
Oauth
|
||||
</Fragment>
|
||||
|
||||
<Fragment slot="subtitle">
|
||||
Connecter Vous aussi avec
|
||||
</Fragment>
|
||||
</CallToAction>
|
||||
</Layout>
|
||||
|
||||
<script>
|
||||
const btn = document.querySelectorAll('.oauth-btn')
|
||||
btn.forEach((item: Element) =>(item.addEventListener('click', (ev) =>{
|
||||
document.cookie = "provider" + "=" + item.getAttribute('data-cookie') + "; path=/";
|
||||
})))
|
||||
</script>
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
|
@ -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'){
|
||||
|
Loading…
x
Reference in New Issue
Block a user