diff --git a/v2/thirdparty/custom-ui/thirdparty-login.mdx b/v2/thirdparty/custom-ui/thirdparty-login.mdx index c467c7501..b24652fe8 100644 --- a/v2/thirdparty/custom-ui/thirdparty-login.mdx +++ b/v2/thirdparty/custom-ui/thirdparty-login.mdx @@ -415,49 +415,45 @@ For android we also need to provide a way for the web login flow to redirect bac import ^{recipeNameCapitalLetters} from "supertokens-node/recipe/^{codeImportRecipeName}"; ^{recipeNameCapitalLetters}.init({ - ^{nodeSignInUpFeatureStart} // highlight-start - override: { - apis: (original) => { - return { - ...original, - appleRedirectHandlerPOST: async (input) => { - if (original.appleRedirectHandlerPOST === undefined) { - throw Error("Should never come here"); + override: { + apis: (original) => { + return { + ...original, + appleRedirectHandlerPOST: async (input) => { + if (original.appleRedirectHandlerPOST === undefined) { + throw Error("Should never come here"); + } + + // inut.formPostInfoFromProvider contains all the query params attached by Apple + const stateInBase64 = input.formPostInfoFromProvider.state; + + // The web SDKs add a default state + if (stateInBase64 === undefined) { + // Redirect to android app + // We create a dummy URL to create the query string + const dummyUrl = new URL("http://localhost:8080"); + for (const [key, value] of Object.entries(input.formPostInfoFromProvider)) { + dummyUrl.searchParams.set(key, `${value}`); } - // inut.formPostInfoFromProvider contains all the query params attached by Apple - const stateInBase64 = input.formPostInfoFromProvider.state; - - // The web SDKs add a default state - if (stateInBase64 === undefined) { - // Redirect to android app - // We create a dummy URL to create the query string - const dummyUrl = new URL("http://localhost:8080"); - for (const [key, value] of Object.entries(input.formPostInfoFromProvider)) { - dummyUrl.searchParams.set(key, `${value}`); - } - - const queryString = dummyUrl.searchParams.toString(); - // Refer to the README of sign_in_with_apple to understand what this url is - const redirectUrl = `intent://callback?${queryString}#Intent;package=YOUR.PACKAGE.IDENTIFIER;scheme=signinwithapple;end`; - - input.options.res.setHeader("Location", redirectUrl, false); - input.options.res.setStatusCode(303); - input.options.res.sendHTMLResponse(""); - } else { - // For the web flow we can use the original implementation - original.appleRedirectHandlerPOST(input); - } - }, - }; - }, + const queryString = dummyUrl.searchParams.toString(); + // Refer to the README of sign_in_with_apple to understand what this url is + const redirectUrl = `intent://callback?${queryString}#Intent;package=YOUR.PACKAGE.IDENTIFIER;scheme=signinwithapple;end`; + + input.options.res.setHeader("Location", redirectUrl, false); + input.options.res.setStatusCode(303); + input.options.res.sendHTMLResponse(""); + } else { + // For the web flow we can use the original implementation + original.appleRedirectHandlerPOST(input); + } + }, + }; }, - // highlight-end - providers: [ - // ... - ], - ^{nodeSignInUpFeatureEnd} + }, + // highlight-end + ^{nodeRecipeInitDefault} }) ``` diff --git a/v2/thirdpartyemailpassword/custom-ui/thirdparty-login.mdx b/v2/thirdpartyemailpassword/custom-ui/thirdparty-login.mdx index e1aa7feaa..3bc4a2cfd 100644 --- a/v2/thirdpartyemailpassword/custom-ui/thirdparty-login.mdx +++ b/v2/thirdpartyemailpassword/custom-ui/thirdparty-login.mdx @@ -418,49 +418,45 @@ For android we also need to provide a way for the web login flow to redirect bac import ^{recipeNameCapitalLetters} from "supertokens-node/recipe/^{codeImportRecipeName}"; ^{recipeNameCapitalLetters}.init({ - ^{nodeSignInUpFeatureStart} // highlight-start - override: { - apis: (original) => { - return { - ...original, - appleRedirectHandlerPOST: async (input) => { - if (original.appleRedirectHandlerPOST === undefined) { - throw Error("Should never come here"); + override: { + apis: (original) => { + return { + ...original, + appleRedirectHandlerPOST: async (input) => { + if (original.appleRedirectHandlerPOST === undefined) { + throw Error("Should never come here"); + } + + // inut.formPostInfoFromProvider contains all the query params attached by Apple + const stateInBase64 = input.formPostInfoFromProvider.state; + + // The web SDKs add a default state + if (stateInBase64 === undefined) { + // Redirect to android app + // We create a dummy URL to create the query string + const dummyUrl = new URL("http://localhost:8080"); + for (const [key, value] of Object.entries(input.formPostInfoFromProvider)) { + dummyUrl.searchParams.set(key, `${value}`); } - // inut.formPostInfoFromProvider contains all the query params attached by Apple - const stateInBase64 = input.formPostInfoFromProvider.state; - - // The web SDKs add a default state - if (stateInBase64 === undefined) { - // Redirect to android app - // We create a dummy URL to create the query string - const dummyUrl = new URL("http://localhost:8080"); - for (const [key, value] of Object.entries(input.formPostInfoFromProvider)) { - dummyUrl.searchParams.set(key, `${value}`); - } - - const queryString = dummyUrl.searchParams.toString(); - // Refer to the README of sign_in_with_apple to understand what this url is - const redirectUrl = `intent://callback?${queryString}#Intent;package=YOUR.PACKAGE.IDENTIFIER;scheme=signinwithapple;end`; - - input.options.res.setHeader("Location", redirectUrl, false); - input.options.res.setStatusCode(303); - input.options.res.sendHTMLResponse(""); - } else { - // For the web flow we can use the original implementation - original.appleRedirectHandlerPOST(input); - } - }, - }; - }, + const queryString = dummyUrl.searchParams.toString(); + // Refer to the README of sign_in_with_apple to understand what this url is + const redirectUrl = `intent://callback?${queryString}#Intent;package=YOUR.PACKAGE.IDENTIFIER;scheme=signinwithapple;end`; + + input.options.res.setHeader("Location", redirectUrl, false); + input.options.res.setStatusCode(303); + input.options.res.sendHTMLResponse(""); + } else { + // For the web flow we can use the original implementation + original.appleRedirectHandlerPOST(input); + } + }, + }; }, - // highlight-end - providers: [ - // ... - ], - ^{nodeSignInUpFeatureEnd} + }, + // highlight-end + ^{nodeRecipeInitDefault} }) ``` diff --git a/v2/thirdpartypasswordless/custom-ui/thirdparty-login.mdx b/v2/thirdpartypasswordless/custom-ui/thirdparty-login.mdx index e784682ab..1927ddf07 100644 --- a/v2/thirdpartypasswordless/custom-ui/thirdparty-login.mdx +++ b/v2/thirdpartypasswordless/custom-ui/thirdparty-login.mdx @@ -418,49 +418,45 @@ For android we also need to provide a way for the web login flow to redirect bac import ^{recipeNameCapitalLetters} from "supertokens-node/recipe/^{codeImportRecipeName}"; ^{recipeNameCapitalLetters}.init({ - ^{nodeSignInUpFeatureStart} // highlight-start - override: { - apis: (original) => { - return { - ...original, - appleRedirectHandlerPOST: async (input) => { - if (original.appleRedirectHandlerPOST === undefined) { - throw Error("Should never come here"); + override: { + apis: (original) => { + return { + ...original, + appleRedirectHandlerPOST: async (input) => { + if (original.appleRedirectHandlerPOST === undefined) { + throw Error("Should never come here"); + } + + // inut.formPostInfoFromProvider contains all the query params attached by Apple + const stateInBase64 = input.formPostInfoFromProvider.state; + + // The web SDKs add a default state + if (stateInBase64 === undefined) { + // Redirect to android app + // We create a dummy URL to create the query string + const dummyUrl = new URL("http://localhost:8080"); + for (const [key, value] of Object.entries(input.formPostInfoFromProvider)) { + dummyUrl.searchParams.set(key, `${value}`); } - // inut.formPostInfoFromProvider contains all the query params attached by Apple - const stateInBase64 = input.formPostInfoFromProvider.state; - - // The web SDKs add a default state - if (stateInBase64 === undefined) { - // Redirect to android app - // We create a dummy URL to create the query string - const dummyUrl = new URL("http://localhost:8080"); - for (const [key, value] of Object.entries(input.formPostInfoFromProvider)) { - dummyUrl.searchParams.set(key, `${value}`); - } - - const queryString = dummyUrl.searchParams.toString(); - // Refer to the README of sign_in_with_apple to understand what this url is - const redirectUrl = `intent://callback?${queryString}#Intent;package=YOUR.PACKAGE.IDENTIFIER;scheme=signinwithapple;end`; - - input.options.res.setHeader("Location", redirectUrl, false); - input.options.res.setStatusCode(303); - input.options.res.sendHTMLResponse(""); - } else { - // For the web flow we can use the original implementation - original.appleRedirectHandlerPOST(input); - } - }, - }; - }, + const queryString = dummyUrl.searchParams.toString(); + // Refer to the README of sign_in_with_apple to understand what this url is + const redirectUrl = `intent://callback?${queryString}#Intent;package=YOUR.PACKAGE.IDENTIFIER;scheme=signinwithapple;end`; + + input.options.res.setHeader("Location", redirectUrl, false); + input.options.res.setStatusCode(303); + input.options.res.sendHTMLResponse(""); + } else { + // For the web flow we can use the original implementation + original.appleRedirectHandlerPOST(input); + } + }, + }; }, - // highlight-end - providers: [ - // ... - ], - ^{nodeSignInUpFeatureEnd} + }, + // highlight-end + ^{nodeRecipeInitDefault} }) ```