Oauth OK
All checks were successful
Build Docker Image / run (pull_request) Successful in 1m37s

This commit is contained in:
2024-05-15 23:43:55 +02:00
parent f863a918bf
commit 509a19f0c9
3 changed files with 132 additions and 21 deletions

View File

@ -1,11 +1,28 @@
---
import Layout from 'layouts/Layout.astro';
import AstroUtils from 'libs/AstroUtils';
import { getEnv } from 'libs/Env';
const pb = Astro.locals.pb
const oauths = await pb.collection('users').listAuthMethods();
console.log(JSON.stringify(oauths.authProviders[0]));
let secure = true
if (getEnv('NODE_ENV', 'production') !== 'production') {
secure = false
}
Astro.cookies.set('provider', oauths.authProviders[0],{
httpOnly: true,
path: '/',
secure: secure,
sameSite: 'lax',
maxAge: 365000
})
if(pb.authStore.isValid){
return Astro.redirect("/account")
}
@ -55,21 +72,6 @@ await AstroUtils.wrap(async () => {
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="type" value="discord2FA">
</form>
<a href={oauths.authProviders[1].authUrl + "https%3A%2F%2Fpb-tweb.cb85.fr%2Fapi%2Foauth2-redirect"}>discord?</a>
<a href={oauths.authProviders[0].authUrl + Astro.url.protocol + "//" + Astro.url.host + '/account/oauth'}>discord?</a>
</Layout>
<script>
import 'cross-fetch/polyfill';
import PocketBase from "pocketbase"
import type { OAuth2UrlCallback } from "pocketbase"
const pb = new PocketBase("https://pb-tweb.cb85.fr/")
const discordBtn = document.querySelector<HTMLButtonElement>("#OauthDiscord")
if (discordBtn) {
discordBtn.addEventListener('click', async () =>{
const result = await pb.collection('users').listAuthMethods();
fetch(result.authProviders[0].authUrl)
console.log(result);
})
}
</script>