Skip to content

Commit 64c12a7

Browse files
feat(auth): update better-auth to version 1.4.5 and improve login handling (#1870)
Co-authored-by: Tofik Hasanov <[email protected]>
1 parent 14182e3 commit 64c12a7

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

apps/portal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@types/jszip": "^3.4.1",
1717
"@upstash/ratelimit": "^2.0.5",
1818
"archiver": "^7.0.1",
19-
"better-auth": "^1.3.27",
19+
"better-auth": "^1.4.5",
2020
"class-variance-authority": "^0.7.1",
2121
"geist": "^1.3.1",
2222
"jszip": "^3.10.1",

apps/portal/src/app/actions/login.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { auth } from '@/app/lib/auth';
44
import { createSafeActionClient } from 'next-safe-action';
5+
import { headers } from 'next/headers';
56
import { z } from 'zod';
67

78
const handleServerError = (e: Error) => {
@@ -28,7 +29,7 @@ const handleServerError = (e: Error) => {
2829
}
2930

3031
if (errorMessage.includes('too many attempts')) {
31-
return 'Too many requests. Please try again later.';
32+
return 'Too many requests. Please try again later.';
3233
}
3334

3435
// If we can't match a specific error, throw a generic but helpful message
@@ -46,11 +47,15 @@ export const login = createSafeActionClient({ handleServerError })
4647
}),
4748
)
4849
.action(async ({ parsedInput }) => {
50+
const headersList = await headers();
51+
4952
await auth.api.signInEmailOTP({
53+
headers: headersList,
5054
body: {
5155
email: parsedInput.email,
5256
otp: parsedInput.otp,
5357
},
58+
asResponse: true,
5459
});
5560

5661
return {

apps/portal/src/app/lib/auth.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export const auth = betterAuth({
1212
provider: 'postgresql',
1313
}),
1414
advanced: {
15-
// This will enable us to fall back to DB for ID generation.
16-
// It's important so we can use custom IDs specified in Prisma Schema.
17-
generateId: false,
15+
database: {
16+
// This will enable us to fall back to DB for ID generation.
17+
// It's important so we can use custom IDs specified in Prisma Schema.
18+
generateId: false,
19+
},
1820
},
1921
trustedOrigins: ['http://localhost:3000', 'https://*.trycomp.ai'],
2022
secret: env.AUTH_SECRET!,

bun.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@types/cheerio": "^1.0.0",
99
"@types/react-syntax-highlighter": "^15.5.13",
1010
"@upstash/vector": "^1.2.2",
11+
"better-auth": "1.4.5",
1112
"cheerio": "^1.1.2",
1213
"react-syntax-highlighter": "^15.6.6",
1314
"unpdf": "^1.4.0",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"@types/cheerio": "^1.0.0",
9191
"@types/react-syntax-highlighter": "^15.5.13",
9292
"@upstash/vector": "^1.2.2",
93+
"better-auth": "1.4.5",
9394
"cheerio": "^1.1.2",
9495
"react-syntax-highlighter": "^15.6.6",
9596
"unpdf": "^1.4.0",

0 commit comments

Comments
 (0)