feat: add login & signup flow

This commit is contained in:
Lin, Hung-Shin committed 2023-09-14 18:54:40 +08:00
1 parent f1510df13e
commit f5c465ab69
3 files changed
+166 -22

No files matched your search

+18
View File
@@ -40,6 +40,24 @@ export const login = async (username, password) => {
}
}
export const register = async (username, email, password) => {
try {
const res = await api.post('/auth/register', {
username,
password,
email,
})
const { token } = res.data
myToken.value = token
return true
} catch (err) {
if (err.response?.status === 409) {
return false
}
throw err
}
}
export const logout = () => {
myToken.value = null
}