64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
/**
|
|
* Auth Page Service
|
|
*
|
|
* Processes URL parameters for auth pages and provides structured data.
|
|
* This is a composition service, not an API service.
|
|
*/
|
|
|
|
import { Result } from '@/lib/contracts/Result';
|
|
import { LoginPageDTO } from './types/LoginPageDTO';
|
|
import { ForgotPasswordPageDTO } from './types/ForgotPasswordPageDTO';
|
|
import { ResetPasswordPageDTO } from './types/ResetPasswordPageDTO';
|
|
import { SignupPageDTO } from './types/SignupPageDTO';
|
|
|
|
export interface AuthPageParams {
|
|
returnTo?: string | null;
|
|
token?: string | null;
|
|
}
|
|
|
|
export class AuthPageService {
|
|
async processLoginParams(params: AuthPageParams): Promise<Result<LoginPageDTO, string>> {
|
|
try {
|
|
const returnTo = params.returnTo ?? '/dashboard';
|
|
const hasInsufficientPermissions = params.returnTo !== null;
|
|
|
|
return Result.ok({
|
|
returnTo,
|
|
hasInsufficientPermissions,
|
|
});
|
|
} catch (error) {
|
|
return Result.err('Failed to process login parameters');
|
|
}
|
|
}
|
|
|
|
async processForgotPasswordParams(params: AuthPageParams): Promise<Result<ForgotPasswordPageDTO, string>> {
|
|
try {
|
|
const returnTo = params.returnTo ?? '/auth/login';
|
|
return Result.ok({ returnTo });
|
|
} catch (error) {
|
|
return Result.err('Failed to process forgot password parameters');
|
|
}
|
|
}
|
|
|
|
async processResetPasswordParams(params: AuthPageParams): Promise<Result<ResetPasswordPageDTO, string>> {
|
|
try {
|
|
const token = params.token;
|
|
if (!token) {
|
|
return Result.err('Missing reset token');
|
|
}
|
|
const returnTo = params.returnTo ?? '/auth/login';
|
|
return Result.ok({ token, returnTo });
|
|
} catch (error) {
|
|
return Result.err('Failed to process reset password parameters');
|
|
}
|
|
}
|
|
|
|
async processSignupParams(params: AuthPageParams): Promise<Result<SignupPageDTO, string>> {
|
|
try {
|
|
const returnTo = params.returnTo ?? '/onboarding';
|
|
return Result.ok({ returnTo });
|
|
} catch (error) {
|
|
return Result.err('Failed to process signup parameters');
|
|
}
|
|
}
|
|
} |