diff --git a/src/contexts/UserAuthenticationContext.tsx b/src/contexts/UserAuthenticationContext.tsx index 7545d92..90f2838 100644 --- a/src/contexts/UserAuthenticationContext.tsx +++ b/src/contexts/UserAuthenticationContext.tsx @@ -1,5 +1,5 @@ import type { IuserInformations } from "@/utils/requests/types"; -import { createContext, useContext, useState } from "react"; +import { createContext, useCallback, useContext, useState } from "react"; import type { IauthenticationData } from "./Types"; export interface UserAuthenticationContextProps { isAuthenticated: boolean; @@ -7,6 +7,7 @@ export interface UserAuthenticationContextProps { setAuthenticationData: React.Dispatch>; userInformations: IuserInformations; setUserInformations: React.Dispatch>; + logout: () => void; } export const UserAuthenticationContext = createContext({ @@ -35,6 +36,7 @@ export const UserAuthenticationContext = createContext {}, + logout: () => {}, }); export const UserAuthenticationContextProvider = ({ children }: { children: React.ReactNode }) => { @@ -65,6 +67,35 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac }, }); + const logout = useCallback(() => { + setIsAuthenticated(false); + setAuthenticationData({ + access: "", + refresh: "", + }); + setUserInformations({ + username: "", + email: "", + // biome-ignore lint/style/useNamingConvention: + first_name: "", + // biome-ignore lint/style/useNamingConvention: + last_name: "", + marchand: { + // biome-ignore lint/style/useNamingConvention: + marchand_id: "", + nom: "", + code: "", + adresse: "", + // biome-ignore lint/style/useNamingConvention: + url_succes: "", + // biome-ignore lint/style/useNamingConvention: + url_echec: "", + entreprise: 0, + user: 0, + }, + }); + }, []); + return ( {children} diff --git a/src/screens/UserProfileScreen.tsx b/src/screens/UserProfileScreen.tsx index b63f79d..0677808 100644 --- a/src/screens/UserProfileScreen.tsx +++ b/src/screens/UserProfileScreen.tsx @@ -3,6 +3,7 @@ import {} from "react"; import {} from "react-native"; import { useUserAuthenticationContext } from "@/contexts/UserAuthenticationContext"; +import Button from "@components/Button"; import BackgroundWithBeasyIconAndWhiteContentArea from "@components/backgrounds/BackgroundWithBeasyIconAndWhiteContentArea"; import Text from "@components/bases/Text"; import { LOG } from "@logger"; @@ -11,6 +12,8 @@ const log = LOG.extend("UserProfileScreen"); const UserProfileScreen = () => { log.verbose("UserProfileScreen"); + const { logout } = useUserAuthenticationContext(); + const { userInformations } = useUserAuthenticationContext(); return ( @@ -63,6 +66,13 @@ const UserProfileScreen = () => { +