adding auth store

This commit is contained in:
2025-12-09 17:27:01 +00:00
parent 529fa9d585
commit 9d9ea9ac53
2 changed files with 42 additions and 0 deletions

View File

@@ -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");

View File

@@ -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);
}
}
});