What do I do in this situation? Do I just initialize dummy functions in place of signup
, login
, and logout
?
It seems so unnecessary since they are defined in AuthProvider.
type AuthContext = {
username: null | string,
isAuthenticated: boolean,
signup: (newUsername: string, email: string, password: string, onSuccessCallback: any) => (string | null),
login: (oldUsername: string, password: string, onSuccessCallback: any) => (string | null),
logout: () => void,
}
const AuthContext = createContext<AuthContext>({}); <------- ERROR, cant be empty "{}", I have to initialize it in accordance to "type AuthContext".
const AuthProvider = ({ children }) => {
const [username, setUsername] = useState<null | string>(null);
const [authenticationStatus, setAuthenticationStatus] = useState<Values<typeof AuthEnum>>(AuthEnum.PENDING);
...
const logout = async () => {
await API.logout()
setUsername(null);
setIsAuthenticated(AuthEnum.UNAUTHENTICATED);
}
...
return (
<AuthContext.Provider
value={{
username: username,
authenticationStatus: authenticationStatus,
logout: logout,
}}
children={children}/>
)
}