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,17 +1,18 @@
|
||||
import { createContext, useContext, useState, useEffect, ReactNode } from "react";
|
||||
import { createContext, useContext, useState, ReactNode } from "react";
|
||||
import { trpc } from "@/lib/trpc";
|
||||
|
||||
interface LocalUser {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
username: string | null;
|
||||
email: string | null;
|
||||
role: "admin" | "user" | "readonly";
|
||||
}
|
||||
|
||||
interface LocalAuthContextType {
|
||||
user: LocalUser | null;
|
||||
loading: boolean;
|
||||
login: (email: string, password: string) => Promise<void>;
|
||||
login: (identifier: string, password: string) => Promise<void>;
|
||||
logout: () => Promise<void>;
|
||||
isAuthenticated: boolean;
|
||||
}
|
||||
@@ -34,10 +35,10 @@ export function LocalAuthProvider({ children }: { children: ReactNode }) {
|
||||
const loginMutation = trpc.auth.localLogin.useMutation();
|
||||
const logoutMutation = trpc.auth.localLogout.useMutation();
|
||||
|
||||
const login = async (email: string, password: string) => {
|
||||
const login = async (identifier: string, password: string) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const result = await loginMutation.mutateAsync({ email, password });
|
||||
const result = await loginMutation.mutateAsync({ identifier, password });
|
||||
const localUser = result.user as LocalUser;
|
||||
setUser(localUser);
|
||||
localStorage.setItem(LOCAL_USER_KEY, JSON.stringify(localUser));
|
||||
|
||||
Reference in New Issue
Block a user