Checkpoint: Correction du login : routers.ts utilise maintenant input.identifier au lieu de input.email, LocalAuthContext.tsx mis à jour en conséquence. La connexion par username (adminItinova) fonctionne en recette.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"version": "59dcc8d3",
|
"version": "cf6f7264",
|
||||||
"timestamp": 1776763904784
|
"timestamp": 1776767388974
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
import { createContext, useContext, useState, useEffect, ReactNode } from "react";
|
import { createContext, useContext, useState, ReactNode } from "react";
|
||||||
import { trpc } from "@/lib/trpc";
|
import { trpc } from "@/lib/trpc";
|
||||||
|
|
||||||
interface LocalUser {
|
interface LocalUser {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
email: string;
|
username: string | null;
|
||||||
|
email: string | null;
|
||||||
role: "admin" | "user" | "readonly";
|
role: "admin" | "user" | "readonly";
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LocalAuthContextType {
|
interface LocalAuthContextType {
|
||||||
user: LocalUser | null;
|
user: LocalUser | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
login: (email: string, password: string) => Promise<void>;
|
login: (identifier: string, password: string) => Promise<void>;
|
||||||
logout: () => Promise<void>;
|
logout: () => Promise<void>;
|
||||||
isAuthenticated: boolean;
|
isAuthenticated: boolean;
|
||||||
}
|
}
|
||||||
@@ -34,10 +35,10 @@ export function LocalAuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const loginMutation = trpc.auth.localLogin.useMutation();
|
const loginMutation = trpc.auth.localLogin.useMutation();
|
||||||
const logoutMutation = trpc.auth.localLogout.useMutation();
|
const logoutMutation = trpc.auth.localLogout.useMutation();
|
||||||
|
|
||||||
const login = async (email: string, password: string) => {
|
const login = async (identifier: string, password: string) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const result = await loginMutation.mutateAsync({ email, password });
|
const result = await loginMutation.mutateAsync({ identifier, password });
|
||||||
const localUser = result.user as LocalUser;
|
const localUser = result.user as LocalUser;
|
||||||
setUser(localUser);
|
setUser(localUser);
|
||||||
localStorage.setItem(LOCAL_USER_KEY, JSON.stringify(localUser));
|
localStorage.setItem(LOCAL_USER_KEY, JSON.stringify(localUser));
|
||||||
|
|||||||
@@ -50,9 +50,9 @@ export const appRouter = router({
|
|||||||
}),
|
}),
|
||||||
// Connexion locale
|
// Connexion locale
|
||||||
localLogin: publicProcedure
|
localLogin: publicProcedure
|
||||||
.input(z.object({ email: z.string().min(1), password: z.string().min(1) }))
|
.input(z.object({ identifier: z.string().min(1), password: z.string().min(1) }))
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const result = await loginLocalUser(input.email, input.password);
|
const result = await loginLocalUser(input.identifier, input.password);
|
||||||
// Stocker le token dans un cookie
|
// Stocker le token dans un cookie
|
||||||
const cookieOptions = getSessionCookieOptions(ctx.req);
|
const cookieOptions = getSessionCookieOptions(ctx.req);
|
||||||
ctx.res.cookie("veille_local_auth", result.token, {
|
ctx.res.cookie("veille_local_auth", result.token, {
|
||||||
|
|||||||
11
todo.md
11
todo.md
@@ -55,8 +55,9 @@
|
|||||||
- [x] Menu "Boîte à idées" dans la sidebar accessible à tous les utilisateurs
|
- [x] Menu "Boîte à idées" dans la sidebar accessible à tous les utilisateurs
|
||||||
|
|
||||||
## Authentification username
|
## Authentification username
|
||||||
- [ ] BDD : ajouter colonne username (unique, nullable) dans la table users
|
- [x] BDD : ajouter colonne username (unique, nullable) dans la table users
|
||||||
- [ ] Backend : loginLocalUser cherche par username OU email
|
- [x] Backend : loginLocalUser cherche par username OU email
|
||||||
- [ ] Backend : createLocalUser accepte username optionnel
|
- [x] Backend : createLocalUser accepte username optionnel
|
||||||
- [ ] Frontend : page Gestion utilisateurs affiche et permet de saisir le username
|
- [x] Frontend : page Gestion utilisateurs affiche et permet de saisir le username
|
||||||
- [ ] Mettre à jour le compte adminItinova avec username = adminItinova
|
- [x] Mettre à jour le compte adminItinova avec username = adminItinova
|
||||||
|
- [x] Migration BDD recette : ajouter colonne username dans local_users et recréer compte adminItinova
|
||||||
|
|||||||
Reference in New Issue
Block a user