Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions packages/core/src/auth/handlers/reset-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
prefix?: string
}

export function resetPasswordEmail<const TOptions extends InternalRouteOptions>(options: TOptions) {

Check warning on line 11 in packages/core/src/auth/handlers/reset-password.ts

View workflow job for this annotation

GitHub Actions / ci

'options' is defined but never used. Allowed unused args must match /^_/u
const schema = {
method: 'POST',
path: '/api/auth/reset-password',
Expand Down Expand Up @@ -86,7 +86,7 @@
return createEndpoint(schema, handler)
}

export function validateResetToken<const TOptions extends InternalRouteOptions>(options: TOptions) {

Check warning on line 89 in packages/core/src/auth/handlers/reset-password.ts

View workflow job for this annotation

GitHub Actions / ci

'options' is defined but never used. Allowed unused args must match /^_/u
const schema = {
method: 'POST',
path: '/api/auth/validate-reset-password-token',
Expand All @@ -95,24 +95,40 @@
}),
responses: {
200: z.object({
verification: z.object({
id: z.string(),
identifier: z.string(),
value: z.string().nullable(),
expiresAt: z.date(),
}),
verification: z
.object({
id: z.string(),
identifier: z.string(),
value: z.string().nullable(),
expiresAt: z.date(),
})
.nullable(),
}),
},
} as const satisfies ApiRouteSchema

const handler: ApiRouteHandler<AuthContext, typeof schema> = async (args) => {
const verification = await args.context.internalHandlers.verification.findByIdentifier(
`reset-password:${args.body.token}`
)
try {
const verification = await args.context.internalHandlers.verification.findByIdentifier(
`reset-password:${args.body.token}`
)

if (!verification || verification.expiresAt < new Date()) {
return {
status: 200,
body: { verification: null },
}
}

return {
status: 200,
body: { verification },
return {
status: 200,
body: { verification: verification ?? null },
}
} catch {
return {
status: 200,
body: { verification: null },
}
}
}

Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions packages/next/src/views/auth/login.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useServerFunction } from '../../providers/root'

const schema = z.object({
email: z.string().email({ message: 'Invalid email address' }),
// TODO: custom password validation
password: z
.string()
.min(8, { message: 'Password must be at least 8 characters long' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client'

import { useEffect, useState } from 'react'
import { useForm } from 'react-hook-form'

import { zodResolver } from '@hookform/resolvers/zod'
Expand All @@ -16,6 +15,7 @@ import { useServerFunction } from '../../../providers/root'

const formSchema = z
.object({
// TODO: custom password validation
password: z
.string()
.min(8, { message: 'Password must be at least 8 characters long' })
Expand All @@ -31,38 +31,12 @@ const formSchema = z

interface ResetPasswordClientFormProps {
token?: string
isErrorToken: boolean
}

export function ResetPasswordClientForm({ token }: ResetPasswordClientFormProps) {
const [isErrorToken, setIsErrorToken] = useState<boolean>(false)

export function ResetPasswordClientForm({ token, isErrorToken }: ResetPasswordClientFormProps) {
const serverFunction = useServerFunction()

useEffect(() => {
async function validateToken() {
const tokenResponse = await serverFunction({
method: 'auth.validateResetToken',
body: {
token: token || '',
},
headers: {},
query: {},
pathParams: {},
})

console.log('Token validation response:', tokenResponse)

if (tokenResponse.status !== 200) {
setIsErrorToken(true)
toast.error('Invalid or expired token', {
description: tokenResponse.body.status || 'Failed to validate token',
})
}
}

validateToken()
}, [token])

const form = useForm({
resolver: zodResolver(formSchema),
mode: 'all',
Expand Down
16 changes: 8 additions & 8 deletions packages/next/src/views/auth/reset-password/reset-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ interface ResetPasswordViewProps {
searchParams: { [key: string]: string | string[] }
}

export async function ResetPasswordView({ searchParams }: ResetPasswordViewProps) {
export async function ResetPasswordView({ searchParams, serverConfig }: ResetPasswordViewProps) {
const token = searchParams['token'] as string | undefined

// const tokenResponse = await serverFunction({
// method: 'auth.validateResetToken',
// body: {
// token: token || '',
// },
// })
const validateToken = await serverConfig.endpoints['auth.validateResetToken'].handler({
body: {
token: token || '',
},
context: {},
})

Comment thread
masternonnolnw marked this conversation as resolved.
Outdated
Comment thread
masternonnolnw marked this conversation as resolved.
Outdated
return <ResetPasswordClientForm token={token} />
return <ResetPasswordClientForm token={token} isErrorToken={!validateToken?.body?.verification} />
}
Loading