Some cleanups, added logout hook

This commit is contained in:
2022-09-10 01:34:34 +02:00
parent fc24ce1306
commit e107d358ee
7 changed files with 90 additions and 72 deletions

View File

@@ -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 (