feat: gestion-utilisateur #1
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 node from '@astrojs/node';
|
import tailwind from '@astrojs/tailwind'
|
||||||
import tailwind from "@astrojs/tailwind";
|
import { defineConfig } from 'astro/config'
|
||||||
|
|
||||||
import react from "@astrojs/react";
|
import react from '@astrojs/react'
|
||||||
|
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
// integrations: [tailwind(), test, routing(), version(), buildInfos()],
|
compressHTML: true,
|
||||||
compressHTML: true,
|
build: {
|
||||||
build: {
|
assets: 'assets',
|
||||||
assets: 'assets',
|
inlineStylesheets: 'auto'
|
||||||
inlineStylesheets: 'auto'
|
},
|
||||||
},
|
server: {
|
||||||
server: {
|
host: true,
|
||||||
host: true,
|
port: 3000
|
||||||
port: 3000
|
},
|
||||||
},
|
trailingSlash: 'never',
|
||||||
trailingSlash: 'never',
|
output: 'server',
|
||||||
output: 'server',
|
adapter: node({
|
||||||
adapter: node({
|
mode: 'standalone'
|
||||||
mode: 'standalone'
|
}),
|
||||||
}),
|
integrations: [tailwind(), react()],
|
||||||
integrations: [tailwind(), react()],
|
vite: {
|
||||||
vite: {
|
optimizeDeps: {
|
||||||
optimizeDeps: {
|
include: ['leaflet']
|
||||||
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 PocketBase from 'pocketbase'
|
||||||
import UserObj from 'models/User'
|
|
||||||
import { getEnv } from 'libs/Env'
|
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)
|
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,
|
httpOnly: true,
|
||||||
path: '/',
|
path: '/',
|
||||||
secure: secure,
|
secure: secure,
|
||||||
sameSite: 'Strict',
|
sameSite: 'strict',
|
||||||
maxAge: 365000,
|
maxAge: 365000,
|
||||||
})
|
})
|
||||||
return true
|
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> {
|
export async function getUser(cookies: AstroCookies): Promise<UserObj | null> {
|
||||||
const sessionID = cookies.get('session')?.value
|
const sessionID = cookies.get('session')?.value
|
||||||
|
|
||||||
|
const bpAuth = pb.authStore
|
||||||
|
|
||||||
if(!sessionID){
|
if(!sessionID){
|
||||||
return
|
return null
|
||||||
}
|
}
|
||||||
if(!pb.authStore.isValid){
|
if(!bpAuth.isValid){
|
||||||
return
|
return null
|
||||||
|
}
|
||||||
|
if(!bpAuth){
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(pb.authStore.model)
|
console.log(bpAuth.model)
|
||||||
return pb.authStore.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,
|
httpOnly: true,
|
||||||
path: '/',
|
path: '/',
|
||||||
secure: secure,
|
secure: secure,
|
||||||
sameSite: 'Strict',
|
sameSite: 'strict',
|
||||||
maxAge: 365000,
|
maxAge: 365000,
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ export default interface UserObj extends PBData{
|
|||||||
username: string
|
username: string
|
||||||
email: string
|
email: string
|
||||||
emailVisibility: false
|
emailVisibility: false
|
||||||
password: string | null
|
password: string | undefined
|
||||||
passwordConfirm: string | null
|
passwordConfirm: string | undefined
|
||||||
name: string | null
|
name: string | null
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ 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 { getUser, setUser } from 'libs/AuthUtils';
|
||||||
import UserObj from 'models/User';
|
import type UserObj from 'models/User';
|
||||||
|
|
||||||
const connected = await getUser(Astro.cookies)
|
const connected = await getUser(Astro.cookies)
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ const res = await AstroUtils.wrap(async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const form = await Astro.request.formData()
|
const form = await Astro.request.formData()
|
||||||
const request : UserObj = {
|
const request = {
|
||||||
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,
|
||||||
|
@ -5,4 +5,7 @@
|
|||||||
// hide an issue with typescript
|
// hide an issue with typescript
|
||||||
"noUnusedLocals": false
|
"noUnusedLocals": false
|
||||||
},
|
},
|
||||||
|
"ts-node": {
|
||||||
|
"esm": true
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user