bde148f286
* wip * some extra fixes * stuff kinda works? * need to figure out mocks * need to figure out mocks * fix db listener * gqlgen fix * minor gqlgen watch adjustment * lint fixes * delete old codegen file * converting migrations to ESM * getModuleDIrectory * vitest sort of works * added back ts-vitest * resolve gql double load * fixing test timeout configs * TSC lint fix * fix automate tests * moar debugging * debugging * more debugging * codegen update * server works * yargs migrated * chore(server): getting rid of global mocks for Server ESM (#5046) * got rid of email mock * got rid of comment mocks * got rid of multi region mocks * got rid of stripe mock * admin override mock updated * removed final mock * fixing import.meta.resolve calls * another import.meta.resolve fix * added requested test * nyc ESM fix * removed unneeded deps + linting * yarn lock forgot to commit * tryna fix flakyness * email capture util fix * sendEmail fix * fix TSX check * sender transporter fix + CR comments * merge main fix * test fixx * circleci fix * gqlgen bigint fix * error formatter fix * more error formatting improvements * esmloader added to Dockerfile * more dockerfile fixes * bg jobs fix
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import { Optional } from '@speckle/shared'
|
|
import { EmailVerificationFinalizationError } from '@/modules/emails/errors'
|
|
import { finalizeEmailVerificationFactory } from '@/modules/emails/services/verification/finalize'
|
|
import type { Express } from 'express'
|
|
import { getFrontendOrigin } from '@/modules/shared/helpers/envHelper'
|
|
import {
|
|
deleteVerificationsFactory,
|
|
getPendingTokenFactory
|
|
} from '@/modules/emails/repositories'
|
|
import { db } from '@/db/knex'
|
|
import { markUserAsVerifiedFactory } from '@/modules/core/repositories/users'
|
|
import { withOperationLogging } from '@/observability/domain/businessLogging'
|
|
|
|
export default (app: Express) => {
|
|
app.get('/auth/verifyemail', async (req, res) => {
|
|
const logger = req.log
|
|
try {
|
|
const finalizeEmailVerification = finalizeEmailVerificationFactory({
|
|
getPendingToken: getPendingTokenFactory({ db }),
|
|
markUserAsVerified: markUserAsVerifiedFactory({ db }),
|
|
deleteVerifications: deleteVerificationsFactory({ db })
|
|
})
|
|
|
|
await withOperationLogging(
|
|
async () => await finalizeEmailVerification(req.query.t as Optional<string>),
|
|
{
|
|
logger,
|
|
operationName: 'finalizeEmailVerification',
|
|
operationDescription: 'Finalize email verification'
|
|
}
|
|
)
|
|
return res.redirect(
|
|
new URL('/?emailverifiedstatus=true', getFrontendOrigin()).toString()
|
|
)
|
|
} catch (error) {
|
|
const msg =
|
|
error instanceof EmailVerificationFinalizationError
|
|
? error.message
|
|
: 'Email verification unexpectedly failed'
|
|
logger.info({ err: error }, 'Email verification failed.')
|
|
|
|
return res.redirect(
|
|
new URL(`/?emailverifiederror=${msg}`, getFrontendOrigin()).toString()
|
|
)
|
|
}
|
|
})
|
|
}
|