@@ -8,6 +8,7 @@ import Footer from "./Footer";
88import SuperTokens from "supertokens-auth-react" ;
99import EmailVerification from "supertokens-auth-react/recipe/emailverification" ;
1010import EmailPassword from "supertokens-auth-react/recipe/emailpassword" ;
11+ import Webauthn from "supertokens-auth-react/recipe/webauthn" ;
1112import Passwordless from "supertokens-auth-react/recipe/passwordless" ;
1213import ThirdParty from "supertokens-auth-react/recipe/thirdparty" ;
1314import Multitenancy from "supertokens-auth-react/recipe/multitenancy" ;
@@ -427,6 +428,9 @@ if (enabledRecipes.includes("emailpassword") || enabledRecipes.includes("thirdpa
427428if ( enabledRecipes . includes ( "passwordless" ) || enabledRecipes . includes ( "thirdpartypasswordless" ) ) {
428429 recipeList = [ getPasswordlessConfigs ( testContext ) , ...recipeList ] ;
429430}
431+ if ( enabledRecipes . includes ( "webauthn" ) ) {
432+ recipeList = [ getWebauthnConfigs ( ) , ...recipeList ] ;
433+ }
430434
431435if ( emailVerificationMode !== "OFF" ) {
432436 recipeList . push ( getEmailVerificationConfigs ( testContext ) ) ;
@@ -1147,6 +1151,65 @@ function setIsNewUserToStorage(recipeName, isNewRecipeUser) {
11471151 localStorage . setItem ( "isNewUserCheck" , `${ recipeName } -${ isNewRecipeUser } ` ) ;
11481152}
11491153
1154+ function getWebauthnConfigs ( ) {
1155+ return Webauthn . init ( {
1156+ style : `
1157+ [data-supertokens~=container] {
1158+ font-family: cursive;
1159+ }
1160+ ` ,
1161+ override : {
1162+ functions : ( implementation ) => {
1163+ const log = logWithPrefix ( `ST_LOGS WEBAUTHN OVERRIDE` ) ;
1164+
1165+ return {
1166+ ...implementation ,
1167+ getRegisterOptions ( ...args ) {
1168+ log ( `GET REGISTER OPTIONS` ) ;
1169+ return implementation . getRegisterOptions ( ...args ) ;
1170+ } ,
1171+ registerCredentialWithSignUp ( ...args ) {
1172+ log ( `GET REGISTER OPTIONS WITH SIGN UP` ) ;
1173+
1174+ // We are mocking the popup since it's not possible to
1175+ // test the webauthn popup.
1176+ return {
1177+ status : "OK" ,
1178+ user : { } ,
1179+ fetchResponse : { } ,
1180+ } ;
1181+ } ,
1182+ } ;
1183+ } ,
1184+ } ,
1185+ preAPIHook : async ( context ) => {
1186+ if ( localStorage . getItem ( `SHOW_GENERAL_ERROR` ) ?. includes ( context . action ) ) {
1187+ let errorFromStorage = localStorage . getItem ( "TRANSLATED_GENERAL_ERROR" ) ;
1188+
1189+ if ( context . action === "EMAIL_EXISTS" ) {
1190+ context . url += "&generalError=true" ;
1191+ } else {
1192+ let jsonBody = JSON . parse ( context . requestInit . body ) ;
1193+ jsonBody = {
1194+ ...jsonBody ,
1195+ generalError : true ,
1196+ generalErrorMessage : errorFromStorage === null ? undefined : errorFromStorage ,
1197+ } ;
1198+ context . requestInit . body = JSON . stringify ( jsonBody ) ;
1199+ }
1200+ }
1201+ console . log ( `ST_LOGS WEBAUTHN PRE_API_HOOKS ${ context . action } ` ) ;
1202+ return context ;
1203+ } ,
1204+ getRedirectionURL : async ( context ) => {
1205+ console . log ( `ST_LOGS WEBAUTHN GET_REDIRECTION_URL ${ context . action } ` ) ;
1206+ } ,
1207+ onHandleEvent : async ( context ) => {
1208+ console . log ( `ST_LOGS WEBAUTHN ON_HANDLE_EVENT ${ context . action } ` ) ;
1209+ } ,
1210+ } ) ;
1211+ }
1212+
11501213window . SuperTokens = SuperTokens ;
11511214window . Session = Session ;
11521215window . UserRoleClaim = UserRoles . UserRoleClaim ;
0 commit comments