vip
This commit is contained in:
29
src/stores/auth.ts
Normal file
29
src/stores/auth.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const token = ref(localStorage.getItem('token'))
|
||||
|
||||
async function login(email: string) {
|
||||
try {
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ email: email }),
|
||||
}
|
||||
const res = await fetch('http://localhost:5173/login', options)
|
||||
if (res.ok) {
|
||||
const data: { accessToken: string; refreshToken: string } = await res.json()
|
||||
|
||||
token.value = data.accessToken
|
||||
localStorage.setItem('token', token.value)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
return { token, login }
|
||||
})
|
||||
0
src/stores/chats.ts
Normal file
0
src/stores/chats.ts
Normal file
0
src/stores/messages.ts
Normal file
0
src/stores/messages.ts
Normal file
5
src/stores/sockets.ts
Normal file
5
src/stores/sockets.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useSockets = defineStore('sockets', () => {
|
||||
return {}
|
||||
})
|
||||
0
src/stores/users.ts
Normal file
0
src/stores/users.ts
Normal file
Reference in New Issue
Block a user