File tree Expand file tree Collapse file tree 4 files changed +40
-14
lines changed
Expand file tree Collapse file tree 4 files changed +40
-14
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import Credentials from 'next-auth/providers/credentials';
55import { getUser } from '@/lib/db/queries' ;
66
77import { authConfig } from './auth.config' ;
8+ import { DUMMY_PASSWORD } from '@/lib/constants' ;
89
910interface ExtendedSession extends Session {
1011 user : User ;
@@ -22,11 +23,24 @@ export const {
2223 credentials : { } ,
2324 async authorize ( { email, password } : any ) {
2425 const users = await getUser ( email ) ;
25- if ( users . length === 0 ) return null ;
26- // biome-ignore lint: Forbidden non-null assertion.
27- const passwordsMatch = await compare ( password , users [ 0 ] . password ! ) ;
26+
27+ if ( users . length === 0 ) {
28+ await compare ( password , DUMMY_PASSWORD ) ;
29+ return null ;
30+ }
31+
32+ const [ user ] = users ;
33+
34+ if ( ! user . password ) {
35+ await compare ( password , DUMMY_PASSWORD ) ;
36+ return null ;
37+ }
38+
39+ const passwordsMatch = await compare ( password , user . password ) ;
40+
2841 if ( ! passwordsMatch ) return null ;
29- return users [ 0 ] as any ;
42+
43+ return user as any ;
3044 } ,
3145 } ) ,
3246 ] ,
Original file line number Diff line number Diff line change 1+ import { generateDummyPassword } from './utils' ;
2+
13export const isProductionEnvironment = process . env . NODE_ENV === 'production' ;
24
35export const isTestEnvironment = Boolean (
46 process . env . PLAYWRIGHT_TEST_BASE_URL ||
57 process . env . PLAYWRIGHT ||
68 process . env . CI_PLAYWRIGHT ,
79) ;
10+
11+ export const DUMMY_PASSWORD = generateDummyPassword ( ) ;
Original file line number Diff line number Diff line change 1- import type {
2- CoreAssistantMessage ,
3- CoreToolMessage ,
4- Message ,
5- TextStreamPart ,
6- ToolInvocation ,
7- ToolSet ,
8- UIMessage ,
1+ import {
2+ generateId ,
3+ type CoreAssistantMessage ,
4+ type CoreToolMessage ,
5+ type Message ,
6+ type UIMessage ,
97} from 'ai' ;
108import { type ClassValue , clsx } from 'clsx' ;
119import { twMerge } from 'tailwind-merge' ;
1210
13- import type { DBMessage , Document } from '@/lib/db/schema' ;
11+ import type { Document } from '@/lib/db/schema' ;
12+ import { genSaltSync , hashSync } from 'bcrypt-ts' ;
1413
1514export function cn ( ...inputs : ClassValue [ ] ) {
1615 return twMerge ( clsx ( inputs ) ) ;
@@ -163,3 +162,12 @@ export function getTrailingMessageId({
163162
164163 return trailingMessage . id ;
165164}
165+
166+ export function generateDummyPassword ( ) {
167+ const password = generateId ( 12 ) ;
168+
169+ const salt = genSaltSync ( 10 ) ;
170+ const hash = hashSync ( password , salt ) ;
171+
172+ return hash ;
173+ }
Original file line number Diff line number Diff line change 11{
22 "name" : " ai-chatbot" ,
3- "version" : " 3.0.3 " ,
3+ "version" : " 3.0.4 " ,
44 "private" : true ,
55 "scripts" : {
66 "dev" : " next dev --turbo" ,
You can’t perform that action at this time.
0 commit comments