|
|
|
|
@ -1,12 +1,11 @@
|
|
|
|
|
import { action, atom, computed } from "nanostores";
|
|
|
|
|
import { action, atom } from "nanostores";
|
|
|
|
|
import { api } from "../api";
|
|
|
|
|
|
|
|
|
|
export const token$ = atom("");
|
|
|
|
|
export const userInfoLoading$ = atom(true);
|
|
|
|
|
|
|
|
|
|
export const isAuthorized$ = computed([token$], (token) => token !== "");
|
|
|
|
|
export const isAuthorized$ = atom(false);
|
|
|
|
|
|
|
|
|
|
export const setToken = action(token$, "setToken", (store, newValue) => {
|
|
|
|
|
export const setAuth = action(isAuthorized$, "setAuth", (store, newValue) => {
|
|
|
|
|
store.set(newValue);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -14,7 +13,7 @@ async function checkAuth() {
|
|
|
|
|
try {
|
|
|
|
|
await api.get("/accounts/profile/");
|
|
|
|
|
|
|
|
|
|
setToken("123456");
|
|
|
|
|
setAuth(true);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("Not authorized");
|
|
|
|
|
} finally {
|
|
|
|
|
|