feat: gestion-utilisateur #1
16
front/src/pages/account/index.astro
Normal file
16
front/src/pages/account/index.astro
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
import Layout from 'layouts/Layout.astro';
|
||||||
|
import { getUser } from 'libs/AuthUtils';
|
||||||
|
|
||||||
|
|
||||||
|
const user = await getUser(Astro.cookies);
|
||||||
|
|
||||||
|
if(!user){
|
||||||
|
return Astro.redirect("/account/login");
|
||||||
|
}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title="Account setting">
|
||||||
|
<h1>Bonjour {user.name}</h1>
|
||||||
|
</Layout>
|
@ -2,13 +2,14 @@
|
|||||||
import Layout from "../../layouts/Layout.astro";
|
import Layout from "../../layouts/Layout.astro";
|
||||||
import PocketBase from 'pocketbase';
|
import PocketBase from 'pocketbase';
|
||||||
import AstroUtils from "../../libs/AstroUtils";
|
import AstroUtils from "../../libs/AstroUtils";
|
||||||
import Schema from 'models/Schema'
|
import { getUser, login } from "libs/AuthUtils";
|
||||||
|
|
||||||
|
|
||||||
// const usr = await getUser(Astro.cookies)
|
|
||||||
// if (usr) {
|
const usr = await getUser(Astro.cookies)
|
||||||
|
if (usr) {
|
||||||
// return Astro.redirect(route('/', {message: 'Vous êtes déjà connecté !'}))
|
// return Astro.redirect(route('/', {message: 'Vous êtes déjà connecté !'}))
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
|
||||||
const res = await AstroUtils.wrap(async () => {
|
const res = await AstroUtils.wrap(async () => {
|
||||||
@ -17,20 +18,14 @@ const res = await AstroUtils.wrap(async () => {
|
|||||||
}
|
}
|
||||||
const form = await Astro.request.formData();
|
const form = await Astro.request.formData();
|
||||||
const request = {
|
const request = {
|
||||||
email: form.get("username") as String,
|
user: form.get("username") as string,
|
||||||
password: form.get("password") 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,
|
|
||||||
);
|
|
||||||
|
|
||||||
// after the above you can also access the auth data from the authStore
|
await login(Astro.cookies, request)
|
||||||
console.log(pb.authStore.isValid);
|
|
||||||
console.log(pb.authStore.token);
|
return Astro.redirect("/account")
|
||||||
console.log(pb.authStore.model.id);
|
|
||||||
|
|
||||||
})
|
})
|
||||||
---
|
---
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
import PocketBase from 'pocketbase';
|
import PocketBase from 'pocketbase';
|
||||||
import Layout from '../../layouts/Layout.astro';
|
import Layout from '../../layouts/Layout.astro';
|
||||||
import AstroUtils from '../../libs/AstroUtils';
|
import AstroUtils from '../../libs/AstroUtils';
|
||||||
|
import { getUser, setUser } from 'libs/AuthUtils';
|
||||||
|
import UserObj from 'models/User';
|
||||||
|
|
||||||
//const connected = await getUser(Astro.cookies)
|
const connected = await getUser(Astro.cookies)
|
||||||
|
|
||||||
// if(connected) {
|
if(connected) {
|
||||||
// return Astro.redirect(route('/'))
|
return Astro.redirect(route('/'))
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
|
||||||
const res = await AstroUtils.wrap(async () => {
|
const res = await AstroUtils.wrap(async () => {
|
||||||
@ -15,19 +17,15 @@ const res = await AstroUtils.wrap(async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const form = await Astro.request.formData()
|
const form = await Astro.request.formData()
|
||||||
const request = {
|
const request : UserObj = {
|
||||||
username: form.get("username") as String,
|
username: form.get("username") as string,
|
||||||
name: form.get("name") as String,
|
name: form.get("name") as string,
|
||||||
email: form.get("email") as String,
|
email: form.get("email") as string,
|
||||||
password: form.get("password") as String,
|
password: form.get("password") as string,
|
||||||
passwordConfirm: form.get("passwordConfirm") as String,
|
passwordConfirm: form.get("passwordConfirm") as string,
|
||||||
emailVisibility: false
|
emailVisibility: false
|
||||||
}
|
}
|
||||||
const pb = new PocketBase('http://127.0.0.1:3001');
|
await setUser(Astro.cookies, request);
|
||||||
|
|
||||||
console.log(request);
|
|
||||||
const record = await pb.collection('users').create(request);
|
|
||||||
console.log(record);
|
|
||||||
|
|
||||||
})
|
})
|
||||||
---
|
---
|
||||||
|
Loading…
x
Reference in New Issue
Block a user