This commit is contained in:
parent
06bdeff188
commit
02e84ed9d6
@ -1,16 +1,18 @@
|
||||
---
|
||||
import Layout from 'layouts/Layout.astro';
|
||||
import { getUser } from 'libs/AuthUtils';
|
||||
import Layout from 'layouts/Layout.astro'
|
||||
import PocketBase from 'pocketbase'
|
||||
|
||||
|
||||
const user = await getUser(Astro.cookies);
|
||||
const pb = Astro.locals.pb as PocketBase
|
||||
const auth = pb.authStore
|
||||
const user = auth.model
|
||||
|
||||
if(!user){
|
||||
if(!auth.isValid){
|
||||
return Astro.redirect("/account/login");
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
<Layout title="Account setting">
|
||||
<h1>Bonjour {user.name}</h1>
|
||||
<h1>Bonjour {user!.name}</h1>
|
||||
</Layout>
|
||||
|
@ -1,29 +1,33 @@
|
||||
---
|
||||
import Layout from "../../layouts/Layout.astro";
|
||||
import PocketBase from 'pocketbase';
|
||||
import AstroUtils from "../../libs/AstroUtils";
|
||||
import { getUser, login } from "libs/AuthUtils";
|
||||
import Layout from "layouts/Layout.astro";
|
||||
import AstroUtils from "libs/AstroUtils";
|
||||
import PocketBase from 'pocketbase'
|
||||
|
||||
|
||||
const pb = Astro.locals.pb as PocketBase
|
||||
|
||||
const usr = await getUser(Astro.cookies)
|
||||
if (usr) {
|
||||
// return Astro.redirect(route('/', {message: 'Vous êtes déjà connecté !'}))
|
||||
if(pb.authStore.isValid){
|
||||
return Astro.redirect("/account")
|
||||
}
|
||||
|
||||
|
||||
const res = await AstroUtils.wrap(async () => {
|
||||
if (Astro.request.method !== 'POST') {
|
||||
return
|
||||
}
|
||||
// FIXME checké si utilisateur deja connecté
|
||||
const locals = Astro.locals
|
||||
|
||||
const form = await Astro.request.formData();
|
||||
const request = {
|
||||
user: form.get("username") as string,
|
||||
password: form.get("password") as string
|
||||
}
|
||||
|
||||
|
||||
await login(Astro.cookies, request)
|
||||
try {
|
||||
await locals.pb.collection('users').authWithPassword(request.user,request.password);
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
return Astro.redirect("/account")
|
||||
|
||||
|
@ -1,18 +1,16 @@
|
||||
---
|
||||
import PocketBase from 'pocketbase';
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
import AstroUtils from '../../libs/AstroUtils';
|
||||
import { getUser, setUser } from 'libs/AuthUtils';
|
||||
import type UserObj from 'models/User';
|
||||
import Layout from 'layouts/Layout.astro';
|
||||
import AstroUtils from 'libs/AstroUtils';
|
||||
import PocketBase from 'pocketbase'
|
||||
|
||||
const connected = await getUser(Astro.cookies)
|
||||
|
||||
if(connected) {
|
||||
return Astro.redirect(route('/'))
|
||||
const pb = Astro.locals.pb as PocketBase
|
||||
|
||||
if(pb.authStore.isValid){
|
||||
return Astro.redirect("/account")
|
||||
}
|
||||
|
||||
|
||||
const res = await AstroUtils.wrap(async () => {
|
||||
await AstroUtils.wrap(async () => {
|
||||
if (Astro.request.method !== 'POST'){
|
||||
return
|
||||
}
|
||||
@ -24,8 +22,12 @@ const res = await AstroUtils.wrap(async () => {
|
||||
password: form.get("password") as string,
|
||||
passwordConfirm: form.get("passwordConfirm") as string,
|
||||
}
|
||||
await setUser(Astro.cookies, request);
|
||||
|
||||
try{
|
||||
await pb.collection('users').create(request)
|
||||
return Astro.redirect('account/login')
|
||||
}catch(e){
|
||||
console.log(e);
|
||||
}
|
||||
})
|
||||
---
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user