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:
Hayden 2023-02-17 21:57:21 -09:00 committed by GitHub
parent bd321af29f
commit 12975ce26e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 204 additions and 86 deletions

View file

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