@@ -29,26 +29,30 @@ router.get('/enroll_factor', (req: Request, res: Response) => {
2929 res . render ( 'enroll_factor.ejs' )
3030} )
3131
32- router . post ( '/enroll_new_factor' , async ( req : Request , res : Response ) => {
33- if ( req . body . type === 'sms' ) {
34- const phone_number : string = req . body . phone_number
32+ router . post ( '/enroll_sms_factor' , async ( req : Request , res : Response ) => {
33+ const phone_number : string = req . body . phone_number
34+ const new_factor : Factor = await workos . mfa . enrollFactor ( {
35+ type : 'sms' ,
36+ phoneNumber : phone_number ,
37+ } )
3538
36- const new_factor : Factor = await workos . mfa . enrollFactor ( {
37- type : 'sms' ,
38- phoneNumber : phone_number ,
39- } )
40- factors . push ( new_factor )
41- } else {
42- const new_factor : Factor = await workos . mfa . enrollFactor ( {
43- type : 'totp' ,
44- issuer : req . body . totp_issuer ,
45- user : req . body . totp_user ,
46- } )
47- factors . push ( new_factor )
48- }
39+ factors . push ( new_factor )
4940 res . redirect ( '/' )
5041} )
5142
43+ router . post ( '/enroll_totp_factor' , async ( req : Request , res : Response ) => {
44+ const { type, issuer, user } : { type : "totp" , issuer : string , user : string } = req . body
45+ const new_factor = await workos . mfa . enrollFactor ( {
46+ type,
47+ issuer,
48+ user
49+ } )
50+
51+ factors . push ( new_factor )
52+ res . json ( new_factor . totp . qr_code )
53+ } )
54+
55+
5256router . get ( '/factor_detail/:id' , async ( req : Request , res : Response ) => {
5357 const factor = factors . filter ( ( factor ) => {
5458 return factor . id == req . params . id
0 commit comments