diff --git a/nginx/vue/src/main.js b/nginx/vue/src/main.js index 9c06e03..976321b 100644 --- a/nginx/vue/src/main.js +++ b/nginx/vue/src/main.js @@ -1,9 +1,11 @@ import { createApp } from "vue"; +import { createPinia } from "pinia"; import App from "./App.vue"; import router from "./router"; const app = createApp(App); app.use(router); +app.use(createPinia()); app.mount("#app"); diff --git a/nginx/vue/src/stores/auth.js b/nginx/vue/src/stores/auth.js new file mode 100644 index 0000000..a3bcd32 --- /dev/null +++ b/nginx/vue/src/stores/auth.js @@ -0,0 +1,40 @@ +import { defineStore } from "pinia"; +import { computed, ref } from "vue"; +import axios from "axios"; + +export const useAuthStore = defineStore("auth", () => { + const user = ref({}); + + function logOut() { + user.value = {}; + } + + async function logIn(username, password) { + try { + const res = await axios.post("/api/auth/login", { + username, + password, + }); + } catch (err) { + console.error(err); + } + } + + async function refreshToken() { + try { + const res = await axios.post("/api/auth/refresh"); + user.value = res.data; + } catch (err) { + console.log(err); + } + } + + async function checkToken() { + try { + const res = await axios.get("/api/auth/check"); + user.value = res.data; + } catch (err) { + console.log(err); + } + } +});