fetch auth session data from token
This commit is contained in:
@@ -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`,
|
||||
|
||||
Reference in New Issue
Block a user