Skip to content

Commit

Permalink
Merge pull request #725 from supertokens/apple-fixes
Browse files Browse the repository at this point in the history
Fix apple sign in snippets
  • Loading branch information
rishabhpoddar authored Oct 4, 2023
2 parents 94b5c65 + be1401b commit 20ef438
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 117 deletions.
74 changes: 35 additions & 39 deletions v2/thirdparty/custom-ui/thirdparty-login.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
})
```

Expand Down
74 changes: 35 additions & 39 deletions v2/thirdpartyemailpassword/custom-ui/thirdparty-login.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
})
```

Expand Down
74 changes: 35 additions & 39 deletions v2/thirdpartypasswordless/custom-ui/thirdparty-login.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
})
```

Expand Down

0 comments on commit 20ef438

Please sign in to comment.