Stupid basic auth
This commit is contained in:
@@ -1,11 +1,34 @@
|
||||
import React, {createContext, useContext, useReducer} from 'react';
|
||||
|
||||
const initialState = {user: {auth: false}};
|
||||
|
||||
const reducer = (state, action) => {
|
||||
console.log(state, action);
|
||||
|
||||
switch (action.type) {
|
||||
case 'login':
|
||||
return {
|
||||
...state,
|
||||
user: action.user
|
||||
}
|
||||
case 'logout':
|
||||
return {
|
||||
...state,
|
||||
user: action.user
|
||||
}
|
||||
default: return state;
|
||||
}
|
||||
};
|
||||
|
||||
export const StateContext = createContext(null);
|
||||
|
||||
export const StateProvider = ({reducer, initialState, children}) => (
|
||||
<StateContext.Provider value={useReducer(reducer, initialState)}>
|
||||
{children}
|
||||
</StateContext.Provider>
|
||||
);
|
||||
export const StateProvider = ({children}) => {
|
||||
|
||||
return (
|
||||
<StateContext.Provider value={useReducer(reducer, initialState )}>
|
||||
{children}
|
||||
</StateContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export const useStateValue = () => useContext(StateContext);
|
||||
|
||||
Reference in New Issue
Block a user