initial
This commit is contained in:
commit
72c796c429
21 changed files with 4956 additions and 0 deletions
41
src/stores/authStore.js
Normal file
41
src/stores/authStore.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { defineStore } from 'pinia';
|
||||
import { computed, ref } from 'vue';
|
||||
import apiClient from '@/services/apiClient';
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
// state
|
||||
const accessToken = ref(null)
|
||||
const user = ref(null)
|
||||
|
||||
// getters
|
||||
const isAuthenticated = computed(() => !!accessToken.value)
|
||||
|
||||
// actions
|
||||
const login = async (email, password) => {
|
||||
try {
|
||||
const response = await apiClient.post(
|
||||
"/user/login",
|
||||
{ email, password }
|
||||
)
|
||||
const { access_token } = response.data
|
||||
accessToken.value = access_token
|
||||
|
||||
console.log('Email', email)
|
||||
console.log('Password', password)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
console.log('logout placeholder')
|
||||
}
|
||||
|
||||
return {
|
||||
accessToken,
|
||||
user,
|
||||
isAuthenticated,
|
||||
login,
|
||||
logout
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue