Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 17 additions & 13 deletions apps/sim/app/api/auth/forget-password/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ vi.mock('@/lib/core/utils/urls', () => ({
function setupAuthApiMocks(
options: {
operations?: {
forgetPassword?: { success?: boolean; error?: string }
requestPasswordReset?: { success?: boolean; error?: string }
resetPassword?: { success?: boolean; error?: string }
}
} = {}
Expand All @@ -34,7 +34,11 @@ function setupAuthApiMocks(

const { operations = {} } = options
const defaultOperations = {
forgetPassword: { success: true, error: 'Forget password error', ...operations.forgetPassword },
requestPasswordReset: {
success: true,
error: 'Forget password error',
...operations.requestPasswordReset,
},
resetPassword: { success: true, error: 'Reset password error', ...operations.resetPassword },
}

Expand All @@ -50,7 +54,7 @@ function setupAuthApiMocks(
vi.doMock('@/lib/auth', () => ({
auth: {
api: {
forgetPassword: createAuthMethod(defaultOperations.forgetPassword),
requestPasswordReset: createAuthMethod(defaultOperations.requestPasswordReset),
resetPassword: createAuthMethod(defaultOperations.resetPassword),
},
},
Expand All @@ -69,7 +73,7 @@ describe('Forget Password API Route', () => {
it('should send password reset email successfully with same-origin redirectTo', async () => {
setupAuthApiMocks({
operations: {
forgetPassword: { success: true },
requestPasswordReset: { success: true },
},
})

Expand All @@ -87,7 +91,7 @@ describe('Forget Password API Route', () => {
expect(data.success).toBe(true)

const auth = await import('@/lib/auth')
expect(auth.auth.api.forgetPassword).toHaveBeenCalledWith({
expect(auth.auth.api.requestPasswordReset).toHaveBeenCalledWith({
body: {
email: 'test@example.com',
redirectTo: 'https://app.example.com/reset',
Expand All @@ -99,7 +103,7 @@ describe('Forget Password API Route', () => {
it('should reject external redirectTo URL', async () => {
setupAuthApiMocks({
operations: {
forgetPassword: { success: true },
requestPasswordReset: { success: true },
},
})

Expand All @@ -117,13 +121,13 @@ describe('Forget Password API Route', () => {
expect(data.message).toBe('Redirect URL must be a valid same-origin URL')

const auth = await import('@/lib/auth')
expect(auth.auth.api.forgetPassword).not.toHaveBeenCalled()
expect(auth.auth.api.requestPasswordReset).not.toHaveBeenCalled()
})

it('should send password reset email without redirectTo', async () => {
setupAuthApiMocks({
operations: {
forgetPassword: { success: true },
requestPasswordReset: { success: true },
},
})

Expand All @@ -140,7 +144,7 @@ describe('Forget Password API Route', () => {
expect(data.success).toBe(true)

const auth = await import('@/lib/auth')
expect(auth.auth.api.forgetPassword).toHaveBeenCalledWith({
expect(auth.auth.api.requestPasswordReset).toHaveBeenCalledWith({
body: {
email: 'test@example.com',
redirectTo: undefined,
Expand All @@ -163,7 +167,7 @@ describe('Forget Password API Route', () => {
expect(data.message).toBe('Email is required')

const auth = await import('@/lib/auth')
expect(auth.auth.api.forgetPassword).not.toHaveBeenCalled()
expect(auth.auth.api.requestPasswordReset).not.toHaveBeenCalled()
})

it('should handle empty email', async () => {
Expand All @@ -182,15 +186,15 @@ describe('Forget Password API Route', () => {
expect(data.message).toBe('Please provide a valid email address')

const auth = await import('@/lib/auth')
expect(auth.auth.api.forgetPassword).not.toHaveBeenCalled()
expect(auth.auth.api.requestPasswordReset).not.toHaveBeenCalled()
})

it('should handle auth service error with message', async () => {
const errorMessage = 'User not found'

setupAuthApiMocks({
operations: {
forgetPassword: {
requestPasswordReset: {
success: false,
error: errorMessage,
},
Expand Down Expand Up @@ -222,7 +226,7 @@ describe('Forget Password API Route', () => {
vi.doMock('@/lib/auth', () => ({
auth: {
api: {
forgetPassword: vi.fn().mockRejectedValue('Unknown error'),
requestPasswordReset: vi.fn().mockRejectedValue('Unknown error'),
},
},
}))
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/auth/forget-password/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function POST(request: NextRequest) {

const { email, redirectTo } = validationResult.data

await auth.api.forgetPassword({
await auth.api.requestPasswordReset({
body: {
email,
redirectTo,
Expand Down
10 changes: 7 additions & 3 deletions apps/sim/app/api/auth/reset-password/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
function setupAuthApiMocks(
options: {
operations?: {
forgetPassword?: { success?: boolean; error?: string }
requestPasswordReset?: { success?: boolean; error?: string }
resetPassword?: { success?: boolean; error?: string }
}
} = {}
Expand All @@ -30,7 +30,11 @@ function setupAuthApiMocks(

const { operations = {} } = options
const defaultOperations = {
forgetPassword: { success: true, error: 'Forget password error', ...operations.forgetPassword },
requestPasswordReset: {
success: true,
error: 'Forget password error',
...operations.requestPasswordReset,
},
resetPassword: { success: true, error: 'Reset password error', ...operations.resetPassword },
}

Expand All @@ -46,7 +50,7 @@ function setupAuthApiMocks(
vi.doMock('@/lib/auth', () => ({
auth: {
api: {
forgetPassword: createAuthMethod(defaultOperations.forgetPassword),
requestPasswordReset: createAuthMethod(defaultOperations.requestPasswordReset),
resetPassword: createAuthMethod(defaultOperations.resetPassword),
},
},
Expand Down
10 changes: 5 additions & 5 deletions apps/sim/lib/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export const auth = betterAuth({
sendVerificationOnSignUp: isEmailVerificationEnabled, // Auto-send verification OTP on signup when verification is required
throwOnMissingCredentials: true,
throwOnInvalidCredentials: true,
sendResetPassword: async ({ user, url, token }, request) => {
sendResetPassword: async ({ user, url, token }, ctx) => {
const username = user.name || ''

const html = await renderPasswordResetEmail(username, url)
Expand Down Expand Up @@ -542,7 +542,7 @@ export const auth = betterAuth({
plugins: [
nextCookies(),
oneTimeToken({
expiresIn: 24 * 60 * 60, // 24 hours - Socket.IO handles connection persistence with heartbeats
expiresIn: 24 * 60, // 24 hours in minutes - Socket.IO handles connection persistence with heartbeats
}),
customSession(async ({ user, session }) => ({
user,
Expand Down Expand Up @@ -2876,9 +2876,9 @@ export const auth = betterAuth({

return hasTeamPlan
},
organizationCreation: {
afterCreate: async ({ organization, user }) => {
logger.info('[organizationCreation.afterCreate] Organization created', {
organizationHooks: {
afterCreateOrganization: async ({ organization, member, user }) => {
logger.info('[organizationHooks.afterCreateOrganization] Organization created', {
organizationId: organization.id,
creatorId: user.id,
})
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"@aws-sdk/s3-request-presigner": "^3.779.0",
"@azure/communication-email": "1.0.0",
"@azure/storage-blob": "12.27.0",
"@better-auth/sso": "1.3.12",
"@better-auth/stripe": "1.3.12",
"@better-auth/sso": "1.4.18",
"@better-auth/stripe": "1.4.18",
"@browserbasehq/stagehand": "^3.0.5",
"@cerebras/cerebras_cloud_sdk": "^1.23.0",
"@e2b/code-interpreter": "^2.0.0",
Expand Down Expand Up @@ -82,7 +82,7 @@
"@trigger.dev/sdk": "4.1.2",
"@types/react-window": "2.0.0",
"@types/three": "0.177.0",
"better-auth": "1.3.12",
"better-auth": "1.4.18",
"binary-extensions": "^2.0.0",
"browser-image-compression": "^2.0.2",
"chalk": "5.6.2",
Expand Down
Loading