Change isAuthorized type

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

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

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

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

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

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

Loading…
Cancel
Save