File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
apps/web/pages/api/forgot-password Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,37 @@ import { prisma } from '@linen/database';
55import { getHostFromHeaders } from '@linen/utilities/domain' ;
66import { cors , preflight } from 'utilities/cors' ;
77
8+ async function checkDomain ( host : string ) {
9+ if ( process . env . NODE_ENV === 'development' ) {
10+ return true ;
11+ }
12+ const domain = host . substring ( host . lastIndexOf ( '/' ) + 1 ) ;
13+ if ( domain === 'linen.dev' || domain === 'www.linen.dev' ) {
14+ return true ;
15+ }
16+ const exist = await prisma . accounts . findFirst ( {
17+ where : { redirectDomain : domain } ,
18+ } ) ;
19+ if ( exist ) {
20+ return true ;
21+ }
22+ return false ;
23+ }
24+
825async function create ( request : NextApiRequest , response : NextApiResponse ) {
926 const { email, origin } = JSON . parse ( request . body ) ;
1027
1128 if ( ! email ) {
1229 return response . status ( 400 ) . json ( { error : 'Email is required' } ) ;
1330 }
31+
32+ const host = origin || getHostFromHeaders ( request . headers ) ;
33+ const isValidDomain = await checkDomain ( host ) ;
34+
35+ if ( ! isValidDomain ) {
36+ return response . status ( 400 ) . json ( { error : 'Invalid domain' } ) ;
37+ }
38+
1439 try {
1540 const token = generateToken ( ) ;
1641
@@ -29,7 +54,7 @@ async function create(request: NextApiRequest, response: NextApiResponse) {
2954
3055 await ResetPasswordMailer . send ( {
3156 to : email ,
32- host : origin || getHostFromHeaders ( request . headers ) ,
57+ host,
3358 token,
3459 } ) ;
3560 } catch ( exception ) {
You can’t perform that action at this time.
0 commit comments