This commit is contained in:
parent
b48c842e41
commit
2cc3219b30
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 PocketBase from 'pocketbase';
|
||||
import AstroUtils from "../../libs/AstroUtils";
|
||||
import Schema from 'models/Schema'
|
||||
import { getUser, login } from "libs/AuthUtils";
|
||||
|
||||
|
||||
// const usr = await getUser(Astro.cookies)
|
||||
// if (usr) {
|
||||
// return Astro.redirect(route('/', {message: 'Vous êtes déjà connecté !'}))
|
||||
// }
|
||||
|
||||
const usr = await getUser(Astro.cookies)
|
||||
if (usr) {
|
||||
// return Astro.redirect(route('/', {message: 'Vous êtes déjà connecté !'}))
|
||||
}
|
||||
|
||||
|
||||
const res = await AstroUtils.wrap(async () => {
|
||||
@ -17,20 +18,14 @@ const res = await AstroUtils.wrap(async () => {
|
||||
}
|
||||
const form = await Astro.request.formData();
|
||||
const request = {
|
||||
email: form.get("username") as String,
|
||||
password: form.get("password") as String
|
||||
user: 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,
|
||||
);
|
||||
|
||||
// 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);
|
||||
await login(Astro.cookies, request)
|
||||
|
||||
return Astro.redirect("/account")
|
||||
|
||||
})
|
||||
---
|
||||
|
@ -2,12 +2,14 @@
|
||||
import PocketBase from 'pocketbase';
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
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) {
|
||||
// return Astro.redirect(route('/'))
|
||||
// }
|
||||
if(connected) {
|
||||
return Astro.redirect(route('/'))
|
||||
}
|
||||
|
||||
|
||||
const res = await AstroUtils.wrap(async () => {
|
||||
@ -15,19 +17,15 @@ const res = await AstroUtils.wrap(async () => {
|
||||
return
|
||||
}
|
||||
const form = await Astro.request.formData()
|
||||
const request = {
|
||||
username: form.get("username") as String,
|
||||
name: form.get("name") as String,
|
||||
email: form.get("email") as String,
|
||||
password: form.get("password") as String,
|
||||
passwordConfirm: form.get("passwordConfirm") as String,
|
||||
const request : UserObj = {
|
||||
username: form.get("username") as string,
|
||||
name: form.get("name") as string,
|
||||
email: form.get("email") as string,
|
||||
password: form.get("password") as string,
|
||||
passwordConfirm: form.get("passwordConfirm") as string,
|
||||
emailVisibility: false
|
||||
}
|
||||
const pb = new PocketBase('http://127.0.0.1:3001');
|
||||
|
||||
console.log(request);
|
||||
const record = await pb.collection('users').create(request);
|
||||
console.log(record);
|
||||
await setUser(Astro.cookies, request);
|
||||
|
||||
})
|
||||
---
|
||||
|
Loading…
x
Reference in New Issue
Block a user