You need to sign in or sign up before continuing.
Commit 62d8d125 by G

add a button in the profile screen to logout the user. currently he's not being…

add a button in the profile screen to logout the user. currently he's not being returned to the authentication screen
parent 424d1dc3
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<React.SetStateAction<IauthenticationData>>;
userInformations: IuserInformations;
setUserInformations: React.Dispatch<React.SetStateAction<IuserInformations>>;
logout: () => void;
}
export const UserAuthenticationContext = createContext<UserAuthenticationContextProps>({
......@@ -35,6 +36,7 @@ export const UserAuthenticationContext = createContext<UserAuthenticationContext
},
},
setUserInformations: () => {},
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: <explanation>
first_name: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
last_name: "",
marchand: {
// biome-ignore lint/style/useNamingConvention: <explanation>
marchand_id: "",
nom: "",
code: "",
adresse: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
url_succes: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
url_echec: "",
entreprise: 0,
user: 0,
},
});
}, []);
return (
<UserAuthenticationContext.Provider
value={{
......@@ -73,6 +104,7 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
setAuthenticationData,
userInformations,
setUserInformations,
logout,
}}
>
{children}
......
......@@ -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 = () => {
</Box>
</Box>
<Button
label={"Deconnexion"}
onPress={logout}
variant={"danger"}
textVariants={"white"}
/>
<Text fontWeight={"bold"}>Informations sur le marchand</Text>
<Box
width={"100%"}
......
......@@ -143,6 +143,9 @@ const theme = createTheme({
backgroundColor: "secondary",
color: "white",
},
danger: {
backgroundColor: "softRed",
},
fullError: {
backgroundColor: "softRed",
color: "white",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment