This commit is contained in:
KS Jannette
2026-03-29 01:48:55 -04:00
parent c0aaaedaf1
commit 1418e7f97c
3 changed files with 35 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
import { Routes, Route, Navigate } from "react-router-dom";
import { useAuth } from "./contexts/AuthContext";
import { useContext } from 'react'
import Navbar from "./components/Navbar";
import Login from "./pages/login/Login";
import Signup from "./pages/Signup";
@@ -8,9 +9,11 @@ import Addresses from "./pages/addresses/Addresses";
import Alerts from "./pages/alerts/Alerts";
import AlertHistory from "./pages/alertHistory/AlertHistory";
import Account from "./pages/user_account/Account";
import { AuthProvider } from "./ShopContext";
import useAuth from "./ShopContext";
export default function App() {
const { currentUser, isSubscribed } = useAuth();
const { context } = useContext(ShopContext)
if (!currentUser) {
return (

View File

@@ -33,13 +33,15 @@ export const AuthProvider = ({ children }) => {
const value = {
user: state.name,
user: state.tier
authUser: state.name,
authUserTier: state.tier,
addAuthUser,
logoutAuthUser
};
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
};
const useAuthContext = () => {
const useAuth = () => {
const context = useContext(ShopContext);
if (context === undefined) {
@@ -49,4 +51,4 @@ const useAuthContext = () => {
return context;
};
export default useAuthContext;
export default useAuth;

View File

@@ -1,25 +1,38 @@
import { useReducer } from "react"
const UserAuthContext = createContext();
export const initialState = {
authUser: null,
AuthTier: null
user: null,
tier: null,
};
const authReducer = (state, action) => {
const { type, payload = "FREE_TIER" } = action
const shopReducer = (state, action) => {
const { name, payload } = action;
switch (type) {
case "ADD_AUTH_USER":
console.log("ADD_AUTH_USER", payload);
case "ADD_TO_CART":
console.log("ADD_TO_CART", payload);
return {
...state,
auth: payload
products: payload.products
};
case "REMOVE_FROM_CART":
console.log("REMOVE_FROM_CART", payload);
return {
...state,
products: payload.products
};
case "UPDATE_PRICE":
console.log("UPDATE_PRICE", payload);
return {
...state,
total: payload.total
};
default:
throw new Error(`No case for type ${type} found.`);
throw new Error(`No case for type ${type} found in shopReducer.`);
}
}
};
export default shopReducer
export default shopReducer;