Refactor authentication method to requireUser
Replaced the requireAuth method with requireUser to improve clarity and modified all instances where it was used. Renamed the import throughout multiple files and services and made changes accordingly, thus making it more specific and understandable that a logged-in user is needed. The return type of the method was also updated from Session to User to more accurately reflect the information it provides.
This commit is contained in:
@@ -5,7 +5,7 @@ import { RedirectType, redirect } from 'next/navigation';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Logger } from '@kit/shared/logger';
|
||||
import { requireAuth } from '@kit/supabase/require-auth';
|
||||
import { requireUser } from '@kit/supabase/require-user';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
import { DeletePersonalAccountService } from './services/delete-personal-account.service';
|
||||
@@ -28,17 +28,17 @@ export async function deletePersonalAccountAction(formData: FormData) {
|
||||
}
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
const session = await requireAuth(client);
|
||||
const auth = await requireUser(client);
|
||||
|
||||
if (session.error) {
|
||||
if (auth.error) {
|
||||
Logger.error(`User is not authenticated. Redirecting to login page`);
|
||||
|
||||
redirect(session.redirectTo);
|
||||
redirect(auth.redirectTo);
|
||||
}
|
||||
|
||||
// retrieve user ID and email
|
||||
const userId = session.data.user.id;
|
||||
const userEmail = session.data.user.email ?? null;
|
||||
const userId = auth.data.id;
|
||||
const userEmail = auth.data.email ?? null;
|
||||
|
||||
// create a new instance of the personal accounts service
|
||||
const service = new DeletePersonalAccountService();
|
||||
|
||||
Reference in New Issue
Block a user