feat: gestion-utilisateur #1
46
front/src/pages/account/login.astro
Normal file
46
front/src/pages/account/login.astro
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
---
|
||||||
|
import Layout from "../../layouts/Layout.astro";
|
||||||
|
import PocketBase from 'pocketbase';
|
||||||
|
import AstroUtils from "../../libs/AstroUtils";
|
||||||
|
import Schema from 'models/Schema'
|
||||||
|
|
||||||
|
|
||||||
|
// const usr = await getUser(Astro.cookies)
|
||||||
|
// if (usr) {
|
||||||
|
// return Astro.redirect(route('/', {message: 'Vous êtes déjà connecté !'}))
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
const res = await AstroUtils.wrap(async () => {
|
||||||
|
if (Astro.request.method !== 'POST') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const form = await Astro.request.formData();
|
||||||
|
const request = {
|
||||||
|
email: form.get("username") as String,
|
||||||
|
password: form.get("password") as String
|
||||||
|
}
|
||||||
|
const pb = new PocketBase('http://127.0.0.1:3001');
|
||||||
|
|
||||||
|
const authData = await pb.collection('users').authWithPassword(
|
||||||
|
request.email,
|
||||||
|
request.password,
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(authData)
|
||||||
|
|
||||||
|
// after the above you can also access the auth data from the authStore
|
||||||
|
console.log(pb.authStore.isValid);
|
||||||
|
console.log(pb.authStore.token);
|
||||||
|
console.log(pb.authStore.model.id);
|
||||||
|
|
||||||
|
})
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title="login">
|
||||||
|
<form id="account-creation" method="post" enctype="multipart/form-data">
|
||||||
|
<input required name="username" placeholder="Pseudo ou email"/>
|
||||||
|
<input required name="password" type="password" placeholder="Mot de passe" />
|
||||||
|
<button>Connection</button>
|
||||||
|
</form>
|
||||||
|
</Layout>
|
Loading…
x
Reference in New Issue
Block a user