2 Commits

Author SHA1 Message Date
7c68628456 add register form test 2024-04-20 11:45:39 +02:00
a2290c21e1 add astro util 2024-04-20 11:45:17 +02:00
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,5 @@
export default class AstroUtils {
public static async wrap<T = void>(fn: () => T | Promise<T>) {
return await fn()
}
}

View File

@ -0,0 +1,44 @@
---
import PocketBase from 'pocketbase';
import Layout from '../../layouts/Layout.astro';
import AstroUtils from '../../libs/AstroUtils';
//const connected = await getUser(Astro.cookies)
// if(connected) {
// return Astro.redirect(route('/'))
// }
const res = await AstroUtils.wrap(async () => {
if (Astro.request.method !== 'POST'){
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,
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);
})
---
<Layout title="register">
<form id="account-creation" method="post" enctype="multipart/form-data">
<input required name="name" placeholder="Nom"/>
<input required name="username" placeholder="Prénom"/>
<input required name="email" type="email" placeholder="Renseignez votre email" />
<input required name="password" type="password" placeholder="Créez un mot de passe" />
<input required name="passwordConfirm" type="password" placeholder="Confirmer votre mot de passe" />
<button>Créer un compte</button>
</form>
</Layout>