forked from mirrors/homebox
feat: change auth to use cookies (#301)
* frontend cookie implementation * accept cookies for authentication * remove auth store * add self attr
This commit is contained in:
parent
bd321af29f
commit
12975ce26e
9 changed files with 204 additions and 86 deletions
|
@ -1,5 +1,4 @@
|
|||
<script setup lang="ts">
|
||||
import { useAuthStore } from "~~/stores/auth";
|
||||
useHead({
|
||||
title: "Homebox | Organize and Tag Your Stuff",
|
||||
});
|
||||
|
@ -8,6 +7,8 @@
|
|||
layout: "empty",
|
||||
});
|
||||
|
||||
const ctx = useAuthContext();
|
||||
|
||||
const api = usePublicApi();
|
||||
const toast = useNotifier();
|
||||
|
||||
|
@ -28,8 +29,7 @@
|
|||
}
|
||||
});
|
||||
|
||||
const authStore = useAuthStore();
|
||||
if (!authStore.isTokenExpired) {
|
||||
if (!ctx.isAuthorized()) {
|
||||
navigateTo("/home");
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@
|
|||
|
||||
async function login() {
|
||||
loading.value = true;
|
||||
const { data, error } = await api.login(email.value, loginPassword.value);
|
||||
const { error } = await ctx.login(api, email.value, loginPassword.value);
|
||||
|
||||
if (error) {
|
||||
toast.error("Invalid email or password");
|
||||
|
@ -101,13 +101,6 @@
|
|||
|
||||
toast.success("Logged in successfully");
|
||||
|
||||
// @ts-ignore
|
||||
authStore.$patch({
|
||||
token: data.token,
|
||||
expires: data.expiresAt,
|
||||
attachmentToken: data.attachmentToken,
|
||||
});
|
||||
|
||||
navigateTo("/home");
|
||||
loading.value = false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue