generated from nishkohli96/react-node-ts-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,319 additions
and
615 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
NODE_ENV= | ||
PORT= | ||
DOMAIN= | ||
|
||
# MongoDB | ||
DB_URL= | ||
DB_NAME= | ||
POSTGRES_URL= | ||
|
||
# Postgres | ||
POSTGRES_URL= | ||
|
||
# Stytch | ||
STYTCH_PROJECT_ID= | ||
STYTCH_ORG_ID= | ||
STYTCH_SECRET= | ||
STYTCH_TEST_EMAIL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module.exports = { | ||
extends: ['@nish1896/eslint-config/js'] | ||
extends: [ | ||
'@nish1896/eslint-config/js' | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,18 @@ const env = process.env; | |
export const ENV_VARS = Object.freeze({ | ||
env: env.NODE_ENV ?? 'development', | ||
port: env.PORT ?? 8000, | ||
domain: env.DOMAIN ?? 'http://localhost:8000', | ||
mongoDB: { | ||
url: process.env.DB_URL ?? 'mongodb://localhost:27017', | ||
dbName: process.env.DB_NAME ?? 'SeederDB' | ||
}, | ||
postgresUrl: env.POSTGRES_URL ?? '' | ||
postgresUrl: env.POSTGRES_URL ?? '', | ||
stytch: { | ||
projectId: env.STYTCH_PROJECT_ID ?? '', | ||
orgId: env.STYTCH_ORG_ID ?? '', | ||
secret: env.STYTCH_SECRET ?? '', | ||
testEmail: env.STYTCH_TEST_EMAIL ?? '[email protected]' | ||
} | ||
}); | ||
|
||
export const isProductionEnv = ENV_VARS.env === 'production'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import { ExpressServerEndpoints } from '@csl/react-express'; | ||
import { fileRouter } from './file/controller'; | ||
import { personRouter } from './person/controller'; | ||
import { stytchRouter } from './stytch/controller'; | ||
|
||
export { | ||
fileRouter, | ||
personRouter | ||
}; | ||
export const routesArray = [ | ||
{ | ||
rootPath: ExpressServerEndpoints.files.rootPath, | ||
router: fileRouter | ||
}, | ||
{ | ||
rootPath: ExpressServerEndpoints.people.rootPath, | ||
router: personRouter | ||
}, | ||
{ | ||
rootPath: ExpressServerEndpoints.stytch.rootPath, | ||
router: stytchRouter | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { Request, Response, Router } from 'express'; | ||
import { ExpressServerEndpoints } from '@csl/react-express'; | ||
import { ENV_VARS } from '@/app-constants'; | ||
import stytchService from './service'; | ||
import * as StytchTypes from './types'; | ||
|
||
const stytchRouter = Router(); | ||
const subRoutes = ExpressServerEndpoints.stytch.subRoutes; | ||
|
||
/* POST: /stytch/add-member */ | ||
stytchRouter.post( | ||
`/${subRoutes.addMember}`, | ||
async (req: Request<object, object, StytchTypes.CreateMemberBody>, res: Response) => { | ||
return await stytchService.addMember(res, req.body); | ||
} | ||
); | ||
|
||
/* GET: /stytch/get-member */ | ||
stytchRouter.get( | ||
`/${subRoutes.getMember}/:memberId`, | ||
async (req: Request<StytchTypes.GetMember>, res: Response) => { | ||
return await stytchService.getMember(res, req.params.memberId); | ||
} | ||
); | ||
|
||
/* PATCH: /stytch/update-member */ | ||
stytchRouter.patch( | ||
`/${subRoutes.updateMember}/:memberId`, | ||
async (req: Request<StytchTypes.GetMember, object, StytchTypes.CreateMemberBody>, res: Response) => { | ||
return await stytchService.updateMember(res, req.params.memberId, req.body); | ||
} | ||
); | ||
|
||
/* DELETE: /stytch/unlink-email */ | ||
stytchRouter.delete( | ||
`/${subRoutes.unlinkEmail}/:memberId`, | ||
async (req: Request<StytchTypes.GetMember, object, StytchTypes.EmailPayload>, res: Response) => { | ||
return await stytchService.unlinkEmail(res, req.params.memberId, req.body); | ||
} | ||
); | ||
|
||
/* DELETE: /stytch/delete-member */ | ||
stytchRouter.delete( | ||
`/${subRoutes.deleteMember}/:memberId`, | ||
async (req: Request<StytchTypes.GetMember>, res: Response) => { | ||
return await stytchService.deleteMember(res, req.params.memberId); | ||
} | ||
); | ||
|
||
/* POST: /stytch/migrate-password */ | ||
stytchRouter.post( | ||
`/${subRoutes.migratePassword}`, | ||
async (req: Request<object, object, StytchTypes.SetPassword>, res: Response) => { | ||
return await stytchService.migratePassword(res, req.body); | ||
} | ||
); | ||
|
||
/* POST: /stytch/org-signin */ | ||
stytchRouter.post( | ||
`/${subRoutes.orgSignIn}`, | ||
async (req: Request, res: Response) => { | ||
return await stytchService.sendSignInEmail(res); | ||
} | ||
); | ||
|
||
/* POST: /stytch/magic-link */ | ||
stytchRouter.post( | ||
`/${subRoutes.magicLinkEmail}`, | ||
async (req: Request, res: Response) => { | ||
const redirectURL = `${ENV_VARS.domain}${ExpressServerEndpoints.apiPrefix}${ExpressServerEndpoints.stytch.rootPath}/${subRoutes.magicLinkRedirect}`; | ||
return await stytchService.sendDiscoveryEmail(res, redirectURL); | ||
} | ||
); | ||
|
||
/* GET: /stytch/discovery-redirect */ | ||
stytchRouter.get( | ||
`/${subRoutes.magicLinkRedirect}`, | ||
(req: Request, res: Response) => { | ||
return stytchService.magicLinkRedirect(res); | ||
} | ||
); | ||
|
||
/* GET: /stytch/sms-otp */ | ||
stytchRouter.get( | ||
`/${subRoutes.smsOTP}/:memberId`, | ||
async (req: Request<StytchTypes.GetMember>, res: Response) => { | ||
return await stytchService.sendSMSOtp(res, req.params.memberId); | ||
} | ||
); | ||
|
||
/* POST: /stytch/verify-sms-otp */ | ||
stytchRouter.post( | ||
`/${subRoutes.verifySMSOTP}`, | ||
async (req: Request<object, object, StytchTypes.VerifyCode>, res: Response) => { | ||
return await stytchService.verifySMSOtp(res, req.body); | ||
} | ||
); | ||
|
||
/* POST: /stytch/email-otp */ | ||
stytchRouter.post( | ||
`/${subRoutes.emailOTP}`, | ||
async (req: Request, res: Response) => { | ||
return await stytchService.sendOtp(res); | ||
} | ||
); | ||
|
||
/* POST: /stytch/reset-password */ | ||
stytchRouter.post( | ||
`/${subRoutes.resetPassword}`, | ||
async ( | ||
req: Request<object, object, StytchTypes.EmailPayload>, | ||
res: Response | ||
) => { | ||
const reqBody = req.body; | ||
return await stytchService.resetPassword(res, reqBody); | ||
} | ||
); | ||
|
||
/* POST: /stytch/authenticate/with-password */ | ||
stytchRouter.post( | ||
`/${subRoutes.authenticatePassword}`, | ||
async ( | ||
req: Request<object, object, StytchTypes.UserLogin>, | ||
res: Response | ||
) => { | ||
const reqBody = req.body; | ||
return await stytchService.loginWithPassword(res, reqBody); | ||
} | ||
); | ||
|
||
/* POST: /stytch/password-strength */ | ||
stytchRouter.post( | ||
`/${subRoutes.passwordStrength}`, | ||
async ( | ||
req: Request<object, object, StytchTypes.PasswordStrengthBody>, | ||
res: Response | ||
) => { | ||
const reqBody = req.body; | ||
return await stytchService.checkPasswordStrength(res, reqBody); | ||
} | ||
); | ||
|
||
/* POST: /stytch/authenticate-email-otp */ | ||
stytchRouter.post( | ||
`/${subRoutes.authenticateEmailOTP}`, | ||
async ( | ||
req: Request<object, object, { code: string }>, | ||
res: Response | ||
) => { | ||
const otpCode = req.body.code; | ||
return await stytchService.verifyOtp(res, otpCode); | ||
} | ||
); | ||
|
||
/* GET: /stytch/get-recovery-codes */ | ||
stytchRouter.get( | ||
`/${subRoutes.getRecoveryCodes}/:memberId`, | ||
async ( | ||
req: Request<StytchTypes.GetMember>, | ||
res: Response | ||
) => { | ||
return await stytchService.getRecoveryCodes(res, req.params.memberId); | ||
} | ||
); | ||
|
||
export { stytchRouter }; |
Oops, something went wrong.