fix auth wip
This commit is contained in:
parent
d65335683c
commit
6e43f12a4f
14468
front/package-lock.json
generated
Normal file
14468
front/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,10 @@
|
||||
---
|
||||
|
||||
const pb = Astro.locals.pb
|
||||
const redirectUrl = Astro.url.protocol + "//" + Astro.url.host + '/account/oauth';
|
||||
|
||||
console.log(redirectUrl)
|
||||
|
||||
const params = Astro.url.searchParams
|
||||
|
||||
const code = params.get('code')
|
||||
|
||||
console.log(redirectUrl)
|
||||
console.log(Astro.request.headers.get('cookie'))
|
||||
//TODO socké dans les cookies
|
||||
// load the previously stored provider's data
|
||||
@ -31,12 +27,11 @@ if (provider.state !== params.get('state')) {
|
||||
throw "State parameters don't match.";
|
||||
}
|
||||
|
||||
pb.collection('users').authWithOAuth2Code(
|
||||
await pb.collection('users').authWithOAuth2Code(
|
||||
provider.name,
|
||||
code,
|
||||
provider.codeVerifier,
|
||||
redirectUrl,
|
||||
// pass optional user create data
|
||||
{
|
||||
emailVisibility: false,
|
||||
}
|
||||
@ -44,11 +39,15 @@ pb.collection('users').authWithOAuth2Code(
|
||||
//REDIRECT
|
||||
console.log("oauth OK !!");
|
||||
console.log(JSON.stringify(authData, null, 2));
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.isValid);
|
||||
return Astro.redirect("/account")
|
||||
}).catch((err) => {
|
||||
console.log("oauth fail !!");
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -59,39 +58,5 @@ pb.collection('users').authWithOAuth2Code(
|
||||
<title>OAuth2 redirect page</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="content">Authenticating...</pre>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/gh/pocketbase/js-sdk@master/dist/pocketbase.umd.js"></script>
|
||||
<script type="text/javascript">
|
||||
const pb = new PocketBase("http://127.0.0.1:8090");
|
||||
const redirectUrl = 'http://127.0.0.1:8090/redirect.html';
|
||||
|
||||
// parse the query parameters from the redirected url
|
||||
const params = (new URL(window.location)).searchParams;
|
||||
|
||||
// load the previously stored provider's data
|
||||
const provider = JSON.parse(localStorage.getItem('provider'))
|
||||
|
||||
// compare the redirect's state param and the stored provider's one
|
||||
if (provider.state !== params.get('state')) {
|
||||
throw "State parameters don't match.";
|
||||
}
|
||||
|
||||
// authenticate
|
||||
pb.collection('users').authWithOAuth2Code(
|
||||
provider.name,
|
||||
params.get('code'),
|
||||
provider.codeVerifier,
|
||||
redirectUrl,
|
||||
// pass optional user create data
|
||||
{
|
||||
emailVisibility: false,
|
||||
}
|
||||
).then((authData) => {
|
||||
document.getElementById('content').innerText = JSON.stringify(authData, null, 2);
|
||||
}).catch((err) => {
|
||||
document.getElementById('content').innerText = "Failed to exchange code.\n" + err;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user