@ -22,6 +22,7 @@ import extractProjectIdAndAuthenticate from '../../helpers/extractProjectIdAndAu
import ncMetaAclMw from '../../helpers/ncMetaAclMw' ;
import ncMetaAclMw from '../../helpers/ncMetaAclMw' ;
import { MetaTable } from '../../../utils/globals' ;
import { MetaTable } from '../../../utils/globals' ;
import Noco from '../../../Noco' ;
import Noco from '../../../Noco' ;
import { getAjvValidatorMw } from '../helpers' ;
import { genJwt } from './helpers' ;
import { genJwt } from './helpers' ;
import { randomTokenString } from '../../helpers/stringHelpers' ;
import { randomTokenString } from '../../helpers/stringHelpers' ;
@ -523,15 +524,32 @@ async function renderPasswordReset(req, res): Promise<any> {
const mapRoutes = ( router ) = > {
const mapRoutes = ( router ) = > {
// todo: old api - /auth/signup?tool=1
// todo: old api - /auth/signup?tool=1
router . post ( '/auth/user/signup' , catchError ( signup ) ) ;
router . post (
router . post ( '/auth/user/signin' , catchError ( signin ) ) ;
'/auth/user/signup' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/SignUpReq' ) ,
catchError ( signup )
) ;
router . post (
'/auth/user/signin' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/SignInReq' ) ,
catchError ( signin )
) ;
router . get ( '/auth/user/me' , extractProjectIdAndAuthenticate , catchError ( me ) ) ;
router . get ( '/auth/user/me' , extractProjectIdAndAuthenticate , catchError ( me ) ) ;
router . post ( '/auth/password/forgot' , catchError ( passwordForgot ) ) ;
router . post (
'/auth/password/forgot' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/ForgotPasswordReq' ) ,
catchError ( passwordForgot )
) ;
router . post ( '/auth/token/validate/:tokenId' , catchError ( tokenValidate ) ) ;
router . post ( '/auth/token/validate/:tokenId' , catchError ( tokenValidate ) ) ;
router . post ( '/auth/password/reset/:tokenId' , catchError ( passwordReset ) ) ;
router . post (
'/auth/password/reset/:tokenId' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/PasswordResetReq' ) ,
catchError ( passwordReset )
) ;
router . post ( '/auth/email/validate/:tokenId' , catchError ( emailVerification ) ) ;
router . post ( '/auth/email/validate/:tokenId' , catchError ( emailVerification ) ) ;
router . post (
router . post (
'/user/password/change' ,
'/user/password/change' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/PasswordChangeReq' ) ,
ncMetaAclMw ( passwordChange , 'passwordChange' )
ncMetaAclMw ( passwordChange , 'passwordChange' )
) ;
) ;
router . post ( '/auth/token/refresh' , catchError ( refreshToken ) ) ;
router . post ( '/auth/token/refresh' , catchError ( refreshToken ) ) ;
@ -549,14 +567,26 @@ const mapRoutes = (router) => {
) ;
) ;
// deprecated APIs
// deprecated APIs
router . post ( '/api/v1/db/auth/user/signup' , catchError ( signup ) ) ;
router . post (
router . post ( '/api/v1/db/auth/user/signin' , catchError ( signin ) ) ;
'/api/v1/db/auth/user/signup' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/SignUpReq' ) ,
catchError ( signup )
) ;
router . post (
'/api/v1/db/auth/user/signin' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/SignInReq' ) ,
catchError ( signin )
) ;
router . get (
router . get (
'/api/v1/db/auth/user/me' ,
'/api/v1/db/auth/user/me' ,
extractProjectIdAndAuthenticate ,
extractProjectIdAndAuthenticate ,
catchError ( me )
catchError ( me )
) ;
) ;
router . post ( '/api/v1/db/auth/password/forgot' , catchError ( passwordForgot ) ) ;
router . post (
'/api/v1/db/auth/password/forgot' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/ForgotPasswordReq' ) ,
catchError ( passwordForgot )
) ;
router . post (
router . post (
'/api/v1/db/auth/token/validate/:tokenId' ,
'/api/v1/db/auth/token/validate/:tokenId' ,
catchError ( tokenValidate )
catchError ( tokenValidate )
@ -571,6 +601,7 @@ const mapRoutes = (router) => {
) ;
) ;
router . post (
router . post (
'/api/v1/db/auth/password/change' ,
'/api/v1/db/auth/password/change' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/PasswordChangeReq' ) ,
ncMetaAclMw ( passwordChange , 'passwordChange' )
ncMetaAclMw ( passwordChange , 'passwordChange' )
) ;
) ;
router . post ( '/api/v1/db/auth/token/refresh' , catchError ( refreshToken ) ) ;
router . post ( '/api/v1/db/auth/token/refresh' , catchError ( refreshToken ) ) ;
@ -580,14 +611,26 @@ const mapRoutes = (router) => {
) ;
) ;
// new API
// new API
router . post ( '/api/v1/auth/user/signup' , catchError ( signup ) ) ;
router . post (
router . post ( '/api/v1/auth/user/signin' , catchError ( signin ) ) ;
'/api/v1/auth/user/signup' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/SignUpReq' ) ,
catchError ( signup )
) ;
router . post (
'/api/v1/auth/user/signin' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/SignInReq' ) ,
catchError ( signin )
) ;
router . get (
router . get (
'/api/v1/auth/user/me' ,
'/api/v1/auth/user/me' ,
extractProjectIdAndAuthenticate ,
extractProjectIdAndAuthenticate ,
catchError ( me )
catchError ( me )
) ;
) ;
router . post ( '/api/v1/auth/password/forgot' , catchError ( passwordForgot ) ) ;
router . post (
'/api/v1/auth/password/forgot' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/ForgotPasswordReq' ) ,
catchError ( passwordForgot )
) ;
router . post (
router . post (
'/api/v1/auth/token/validate/:tokenId' ,
'/api/v1/auth/token/validate/:tokenId' ,
catchError ( tokenValidate )
catchError ( tokenValidate )
@ -602,6 +645,7 @@ const mapRoutes = (router) => {
) ;
) ;
router . post (
router . post (
'/api/v1/auth/password/change' ,
'/api/v1/auth/password/change' ,
getAjvValidatorMw ( 'swagger.json#/components/schemas/PasswordChangeReq' ) ,
ncMetaAclMw ( passwordChange , 'passwordChange' )
ncMetaAclMw ( passwordChange , 'passwordChange' )
) ;
) ;
router . post ( '/api/v1/auth/token/refresh' , catchError ( refreshToken ) ) ;
router . post ( '/api/v1/auth/token/refresh' , catchError ( refreshToken ) ) ;