Change isAuthorized type

dev
Platon Yasev 3 years ago
parent 824e9de3e5
commit 3ef3fff739

@ -1,6 +1,6 @@
import { Button } from "antd"; import { Button } from "antd";
import { LogoutOutlined } from "@ant-design/icons"; import { LogoutOutlined } from "@ant-design/icons";
import { setToken } from "./stores/auth"; import { setAuth } from "./stores/auth";
import { api } from "./api"; import { api } from "./api";
export function SignOut() { export function SignOut() {
@ -14,7 +14,7 @@ export function SignOut() {
onClick={async () => { onClick={async () => {
await api.post("accounts/logout/"); await api.post("accounts/logout/");
setToken(""); setAuth(false);
}} }}
/> />
</div> </div>

@ -1,10 +1,12 @@
import axios from "axios"; import axios from "axios";
export const BASE_URL = "https://postnet-dev.selftech.ru";
export const api = axios.create({ export const api = axios.create({
baseURL: baseURL:
import.meta.env.MODE === "development" import.meta.env.MODE === "development"
? "http://localhost:5173/" ? "http://localhost:5173/"
: "https://postnet-dev.selftech.ru/", : `${BASE_URL}/`,
withCredentials: true, withCredentials: true,
xsrfHeaderName: "X-CSRFToken", xsrfHeaderName: "X-CSRFToken",
xsrfCookieName: "csrftoken", xsrfCookieName: "csrftoken",

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

@ -1,6 +1,6 @@
import { atom } from "nanostores"; import { atom } from "nanostores";
import { api } from "../api"; import { api } from "../api";
import { setToken } from "./auth"; import { setAuth } from "./auth";
export class DjangoValidationError extends Error { export class DjangoValidationError extends Error {
errors; errors;
@ -34,7 +34,7 @@ export async function signin(values) {
try { try {
const { data } = await api.post("accounts/login/", values); const { data } = await api.post("accounts/login/", values);
setToken("123456"); setAuth(true);
return data; return data;
} catch (e) { } catch (e) {
var error = DEFAULT_ERROR; var error = DEFAULT_ERROR;

@ -2,14 +2,16 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react"; import react from "@vitejs/plugin-react";
import svgr from "vite-plugin-svgr"; import svgr from "vite-plugin-svgr";
const BASE_URL = "https://postnet-dev.selftech.ru/";
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
base: "/", base: "/",
plugins: [svgr(), react()], plugins: [svgr(), react()],
server: { server: {
proxy: { proxy: {
"/account": "https://postnet-dev.selftech.ru/", "/account": BASE_URL,
"/api": "https://postnet-dev.selftech.ru/", "/api": BASE_URL,
}, },
}, },
css: { css: {

Loading…
Cancel
Save