fetch auth session data from token

This commit is contained in:
2025-07-18 12:11:29 +02:00
parent 026f84b870
commit 1a6c60ff03
19 changed files with 368 additions and 20 deletions

View File

@@ -1,10 +1,12 @@
import { toast } from 'vue-sonner';
import type { ApiResponse } from '~/types/api';
import { getAuthSessionData } from './getSession';
export async function loginUser(
email: string,
password: string
): Promise<{ success: boolean }> {
console.log('logging in...', email, password);
const { data, error } = await useFetch<ApiResponse<{ token: string }>>(
getApiUrl('auth/login'),
{
@@ -30,7 +32,24 @@ export async function loginUser(
};
}
useAuthSession().value = { type: 'WarrenAuth', id: data.value.data.token };
// TODO: Get this data directly from the login request
const sessionData = await getAuthSessionData({
sessionType: 'WarrenAuth',
sessionId: data.value.data.token,
});
if (!sessionData.success) {
return {
success: false,
};
}
useAuthSession().value = {
type: 'WarrenAuth',
id: data.value.data.token,
user: sessionData.user,
expiresAt: sessionData.expiresAt,
};
toast.success('Login', {
description: `Successfully logged in`,