feat: gestion-utilisateur #14
9
front/.vscode/settings.json
vendored
Normal file
9
front/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"editor.quickSuggestions": {
|
||||
"strings": "on"
|
||||
},
|
||||
"tailwindCSS.includeLanguages": {
|
||||
"astro": "html"
|
||||
},
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
}
|
@ -1,30 +1,29 @@
|
||||
import { defineConfig } from 'astro/config';
|
||||
import node from '@astrojs/node';
|
||||
import tailwind from "@astrojs/tailwind";
|
||||
import node from '@astrojs/node'
|
||||
import tailwind from '@astrojs/tailwind'
|
||||
import { defineConfig } from 'astro/config'
|
||||
|
||||
import react from "@astrojs/react";
|
||||
import react from '@astrojs/react'
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
// integrations: [tailwind(), test, routing(), version(), buildInfos()],
|
||||
compressHTML: true,
|
||||
build: {
|
||||
assets: 'assets',
|
||||
inlineStylesheets: 'auto'
|
||||
},
|
||||
server: {
|
||||
host: true,
|
||||
port: 3000
|
||||
},
|
||||
trailingSlash: 'never',
|
||||
output: 'server',
|
||||
adapter: node({
|
||||
mode: 'standalone'
|
||||
}),
|
||||
integrations: [tailwind(), react()],
|
||||
vite: {
|
||||
optimizeDeps: {
|
||||
include: ['leaflet']
|
||||
}
|
||||
}
|
||||
});
|
||||
compressHTML: true,
|
||||
build: {
|
||||
assets: 'assets',
|
||||
inlineStylesheets: 'auto'
|
||||
},
|
||||
server: {
|
||||
host: true,
|
||||
port: 3000
|
||||
},
|
||||
trailingSlash: 'never',
|
||||
output: 'server',
|
||||
adapter: node({
|
||||
mode: 'standalone'
|
||||
}),
|
||||
integrations: [tailwind(), react()],
|
||||
vite: {
|
||||
optimizeDeps: {
|
||||
include: ['leaflet']
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { AstroCookies } from 'astro'
|
||||
import type { AstroCookies } from 'astro'
|
||||
import type UserObj from 'models/User'
|
||||
import PocketBase from 'pocketbase'
|
||||
import UserObj from 'models/User'
|
||||
import { getEnv } from 'libs/Env'
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ export async function clearUser(cookies: AstroCookies): Promise<void> {
|
||||
})
|
||||
}
|
||||
|
||||
export async function login(cookies: AstroCookies, user: {user: string, password: string}): boolean {
|
||||
export async function login(cookies: AstroCookies, user: {user: string, password: string}): Promise<boolean> {
|
||||
|
||||
const authData = await pb.collection('users').authWithPassword(user.user, user.password)
|
||||
|
||||
@ -33,7 +33,7 @@ export async function login(cookies: AstroCookies, user: {user: string, password
|
||||
httpOnly: true,
|
||||
path: '/',
|
||||
secure: secure,
|
||||
sameSite: 'Strict',
|
||||
sameSite: 'strict',
|
||||
maxAge: 365000,
|
||||
})
|
||||
return true
|
||||
@ -44,15 +44,40 @@ export async function login(cookies: AstroCookies, user: {user: string, password
|
||||
export async function getUser(cookies: AstroCookies): Promise<UserObj | null> {
|
||||
const sessionID = cookies.get('session')?.value
|
||||
|
||||
const bpAuth = pb.authStore
|
||||
|
||||
if(!sessionID){
|
||||
return
|
||||
return null
|
||||
}
|
||||
if(!pb.authStore.isValid){
|
||||
return
|
||||
if(!bpAuth.isValid){
|
||||
return null
|
||||
}
|
||||
if(!bpAuth){
|
||||
return null
|
||||
}
|
||||
|
||||
console.log(pb.authStore.model)
|
||||
return pb.authStore.model
|
||||
console.log(bpAuth.model)
|
||||
|
||||
if(!bpAuth.model){
|
||||
return null
|
||||
}
|
||||
|
||||
const output: UserObj = {
|
||||
id: bpAuth.model.id as string,
|
||||
collectionId: bpAuth.model.collectionId as string,
|
||||
collectionName: bpAuth.model.collectionName as string,
|
||||
created: bpAuth.model.created as string,
|
||||
updated: bpAuth.model.updated as string,
|
||||
avatar: bpAuth.model.avatar as string,
|
||||
username: bpAuth.model.username as string,
|
||||
email: bpAuth.model.email as string,
|
||||
emailVisibility: false,
|
||||
name: bpAuth.model.name as string,
|
||||
password: undefined,
|
||||
passwordConfirm: undefined
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
}
|
||||
|
||||
@ -76,7 +101,7 @@ export async function setUser(cookies: AstroCookies, user: UserObj): Promise<voi
|
||||
httpOnly: true,
|
||||
path: '/',
|
||||
secure: secure,
|
||||
sameSite: 'Strict',
|
||||
sameSite: 'strict',
|
||||
maxAge: 365000,
|
||||
})
|
||||
}
|
@ -13,7 +13,7 @@ export default interface UserObj extends PBData{
|
||||
username: string
|
||||
email: string
|
||||
emailVisibility: false
|
||||
password: string | null
|
||||
passwordConfirm: string | null
|
||||
password: string | undefined
|
||||
passwordConfirm: string | undefined
|
||||
name: string | null
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ 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';
|
||||
import type UserObj from 'models/User';
|
||||
|
||||
const connected = await getUser(Astro.cookies)
|
||||
|
||||
@ -17,7 +17,7 @@ const res = await AstroUtils.wrap(async () => {
|
||||
return
|
||||
}
|
||||
const form = await Astro.request.formData()
|
||||
const request : UserObj = {
|
||||
const request = {
|
||||
username: form.get("username") as string,
|
||||
name: form.get("name") as string,
|
||||
email: form.get("email") as string,
|
||||
|
@ -5,4 +5,7 @@
|
||||
// hide an issue with typescript
|
||||
"noUnusedLocals": false
|
||||
},
|
||||
"ts-node": {
|
||||
"esm": true
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user