Some cleanups, added logout hook
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useLocation, useNavigate } from "@solidjs/router";
|
||||
import { useNavigate } from "@solidjs/router";
|
||||
import { createContext, onMount, Show, useContext } from "solid-js";
|
||||
import { createStore } from "solid-js/store";
|
||||
import { UserType } from "supertokens-web-js/recipe/emailpassword";
|
||||
@@ -37,14 +37,15 @@ const AuthProvider = (props: any) => {
|
||||
setStore("isLoading", false);
|
||||
});
|
||||
|
||||
const setCurrentUser = (user: UserType) => {
|
||||
setStore("isAuthenticated", true);
|
||||
setStore("currentUser", user);
|
||||
const setCurrentUser = (user?: UserType) => {
|
||||
if (user) {
|
||||
setStore("isAuthenticated", true);
|
||||
setStore("currentUser", user);
|
||||
}
|
||||
};
|
||||
const removeCurrentUser = () => {
|
||||
setStore("isAuthenticated", false);
|
||||
setStore("currentUser", null);
|
||||
localStorage.removeItem("current_user");
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user