Feature/phone register (#11)

Co-authored-by: ISMAIL MASSERAN <topaz@ISMAILs-Macbook.local>
Co-authored-by: ISMAIL MASSERAN <topaz@Mac.dlinkrouter.local>
Reviewed-on: #11
This commit was merged in pull request #11.
This commit is contained in:
2026-07-14 12:03:22 +08:00
parent 1e50e3d19f
commit b05e074456
160 changed files with 6497 additions and 759 deletions
+55 -17
View File
@@ -5,16 +5,18 @@ import type {
ForgotPasswordResponse,
LoginCredentials,
LoginResponse,
LoginVerificationRequiredData,
RegisterCredentials,
RegisterResponse,
ResendVerificationResponse,
ResetPasswordPayload,
ResetPasswordResponse,
ResendVerificationResponse,
SessionResponse,
SendPhoneVerificationOtpPayload,
SendPhoneVerificationOtpResponse,
SwitchRoleResponse,
VerifyEmailPayload,
VerifyEmailResponse,
VerifyPhoneVerificationOtpPayload,
VerifyPhoneVerificationOtpResponse,
VerifyAuthenticatedPhoneVerificationOtpResponse,
} from '../types/auth.types'
export async function login(credentials: LoginCredentials): Promise<LoginResponse> {
@@ -27,13 +29,48 @@ export async function register(credentials: RegisterCredentials): Promise<Regist
return data
}
export async function verifyEmail(payload: VerifyEmailPayload): Promise<VerifyEmailResponse> {
const { data } = await api.post<VerifyEmailResponse>('/verify-email', payload)
export async function sendPhoneVerificationOtp(
payload: SendPhoneVerificationOtpPayload,
): Promise<SendPhoneVerificationOtpResponse> {
const { data } = await api.post<SendPhoneVerificationOtpResponse>(
'/phone-verification/send',
payload,
)
return data
}
export async function resendVerificationEmail(email: string): Promise<ResendVerificationResponse> {
const { data } = await api.post<ResendVerificationResponse>('/verify-email/resend', { email })
export async function verifyPhoneVerificationOtp(
payload: VerifyPhoneVerificationOtpPayload,
): Promise<VerifyPhoneVerificationOtpResponse> {
const { data } = await api.post<VerifyPhoneVerificationOtpResponse>(
'/phone-verification/verify',
payload,
)
return data
}
export async function sendAuthenticatedPhoneVerificationOtp(
payload: SendPhoneVerificationOtpPayload,
): Promise<SendPhoneVerificationOtpResponse> {
const { data } = await api.post<SendPhoneVerificationOtpResponse>(
'/v1/phone-verification/send',
payload,
)
return data
}
export async function verifyAuthenticatedPhoneVerificationOtp(
payload: VerifyPhoneVerificationOtpPayload,
): Promise<VerifyAuthenticatedPhoneVerificationOtpResponse> {
const { data } = await api.post<VerifyAuthenticatedPhoneVerificationOtpResponse>(
'/v1/phone-verification/verify',
payload,
)
return data
}
export async function sendVerificationEmail(): Promise<ResendVerificationResponse> {
const { data } = await api.post<ResendVerificationResponse>('/v1/email/verification-notification')
return data
}
@@ -73,8 +110,8 @@ export function getRegisterErrorMessage(error: unknown): string {
return getApiErrorMessage(error, 'Registration failed. Please try again.')
}
export function getVerifyEmailErrorMessage(error: unknown): string {
return getApiErrorMessage(error, 'Email verification failed. Please try again.')
export function getPhoneVerificationErrorMessage(error: unknown): string {
return getApiErrorMessage(error, 'Gagal mengesahkan nombor telefon. Sila cuba lagi.')
}
export function getForgotPasswordErrorMessage(error: unknown): string {
@@ -85,15 +122,16 @@ export function getResetPasswordErrorMessage(error: unknown): string {
return getApiErrorMessage(error, 'Gagal menetapkan semula kata laluan. Sila cuba lagi.')
}
export function isAccountPending(user: { status: string } | null | undefined): boolean {
return user?.status === 'pending'
export function isEmailVerified(user: { email_verified_at?: string | null } | null | undefined): boolean {
return Boolean(user?.email_verified_at)
}
export function isLoginVerificationRequired(
response: LoginResponse,
): response is LoginResponse & { data: LoginVerificationRequiredData } {
return 'requires_email_verification' in response.data
&& response.data.requires_email_verification === true
export function isPhoneVerified(user: { phone_verified_at?: string | null } | null | undefined): boolean {
return Boolean(user?.phone_verified_at)
}
export function isAccountPending(user: { status: string } | null | undefined): boolean {
return user?.status === 'pending'
}
export function resolvePostAuthRoute(