Skip to content

Commit

Permalink
Merge pull request #698 from supertokens/account-linking
Browse files Browse the repository at this point in the history
Account linking
rishabhpoddar authored Sep 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 6aaef35 + 135b13f commit c0fb0e7
Showing 197 changed files with 5,518 additions and 2,047 deletions.
62 changes: 62 additions & 0 deletions v2/community/versioning.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
id: versioning
title: Viewing older versions of the documentation
hide_title: true
slug: /versioning
---

# Viewing older versions of the documentation

You can use the [docs](https://github.com/supertokens/docs) repository on Github to check-out and view an older version of the documentation.

## 1. Finding the correct version of the documentation

The [release notes](https://github.com/supertokens/docs/releases) of the Github repo lists all the SDK versions the documentation is comptabile with. Find the correct version for you by looking at the version of the SDK you are using.

For example if you are using `supertokens-node` version `15.2.0` you want to find the version of the docs repository that mentions that it is compatible with

```text
supertokens-node: 15.X.X
```

The release notes only mention the major version of the SDK it supports because all snippets are compatible with patch versions for a given major version.

## 2. Clone the repository and switch to the correct version

Clone the repository:

```bash
git clone https://github.com/supertokens/docs.git
```

Once downloaded, switch to the correct tag. The tag can be found on the releases page next to the version you are trying to use.

```bash
git checkout <TAG>
```

## 3. Setup the documentation project

Navigate to the `v2` folder:

```bash
cd v2/
```

Install all dependencies:

```bash
npm i -d
```

## 4. Run the website locally

From inside the `v2` directory run:

```bash
npm run start
```

This will build the project and start it on `http://localhost:3000` where you can view the full documentation.

If you see a screen that asks you to choose between user docs and contributing docs, use the user docs.
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ EmailPassword.init({
// in this case, they are usually redirected to the main app
} else if (context.action === "SUCCESS") {
let user = context.user;
if (context.isNewUser) {
if (context.isNewRecipeUser && context.user.loginMethods.length === 1) {
// sign up success
} else {
// sign in success
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ EmailPassword.init({

} else if (action === "SEND_RESET_PASSWORD_EMAIL") {

}else if (action === "EMAIL_PASSWORD_SIGN_IN") {
} else if (action === "EMAIL_PASSWORD_SIGN_IN") {

} else if (action === "EMAIL_PASSWORD_SIGN_UP") {

@@ -81,23 +81,32 @@ Also checkout the [session recipe pre API hook](/docs/session/advanced-customiza
import EmailPassword from "supertokens-web-js/recipe/emailpassword"

EmailPassword.init({
postAPIHook: async (context) => {
preAPIHook: async (context) => {
let url = context.url;

// is the fetch config object that contains the header, body etc..
let requestInit = context.requestInit;

let action = context.action;
if (action === "EMAIL_EXISTS") {

} else if (action === "SEND_RESET_PASSWORD_EMAIL") {

} else if (action === "EMAIL_PASSWORD_SIGN_IN") {

} else if (action === "EMAIL_PASSWORD_SIGN_UP") {

} else if (action === "SEND_RESET_PASSWORD_EMAIL") {

} else if (action === "SUBMIT_NEW_PASSWORD") {

}
} else if (action === "VERIFY_EMAIL") {

}

// events such as sign out are in the
// session recipe pre API hook (See the info box below)
return {
requestInit, url
};
},
})
```
@@ -131,23 +140,32 @@ EmailPassword.doesEmailExist({
import supertokensEmailPassword from "supertokens-web-js-script/recipe/emailpassword";

supertokensEmailPassword.init({
postAPIHook: async (context) => {
preAPIHook: async (context) => {
let url = context.url;

// is the fetch config object that contains the header, body etc..
let requestInit = context.requestInit;

let action = context.action;
if (action === "EMAIL_EXISTS") {

} else if (action === "SEND_RESET_PASSWORD_EMAIL") {

} else if (action === "EMAIL_PASSWORD_SIGN_IN") {

} else if (action === "EMAIL_PASSWORD_SIGN_UP") {

} else if (action === "SEND_RESET_PASSWORD_EMAIL") {

} else if (action === "SUBMIT_NEW_PASSWORD") {

} else if (action === "VERIFY_EMAIL") {

}

// events such as sign out are in the
// session recipe pre API hook (See the info box below)
return {
requestInit, url
};
},
})
```
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ EmailPassword.init({
// we are navigating back to where the user was before they authenticated
return redirectToPath;
}
if (context.isNewUser) {
if (context.isNewRecipeUser && context.user.loginMethods.length === 1) {
// user signed up
return "/onboarding"
} else {
Original file line number Diff line number Diff line change
@@ -11,10 +11,9 @@ import {Question}from "/src/components/question"

# How to use

1. You will need to modify the `EmailPassword.init(...)` function call.
2. Component overrides can be configured at `override.components` config object.
3. [Pick a component](#finding-which-component-will-be-overridden) that you'd like to override by its key.
4. Supply a React component against the key you have picked. Your custom component will get the original component as a `prop`.
1. You will have to use the `EmailPasswordComponentsOverrideProvider` component as shown below. make sure that it render the SuperTokens components inside this component.
2. [Pick a component](#finding-which-component-will-be-overridden) that you'd like to override by its key.
3. Supply a React component against the key you have picked. Your custom component will get the original component as a `prop`.

## Example
<FrontendSDKTabs>
29 changes: 15 additions & 14 deletions v2/emailpassword/advanced-customizations/user-context.mdx
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ In order to achieve this, all the API interface and recipe interface functions t

## Example use

Let's take the example mentioned above and implement it in the context of this recipe. First, we override the sign up APIs to add information into the context indicating that it's a sign up API call:
Let's take the example mentioned above and implement it in the context of this recipe. First, we override the sign up function to add information into the context indicating that it's a sign up API call:

<BackendSDKTabs>
<TabItem value="nodejs">
@@ -48,22 +48,22 @@ SuperTokens.init({
EmailPassword.init({
// highlight-start
override: {
apis: (originalImplementation) => {
functions: (originalImplementation) => {
return {
...originalImplementation,
// override sign up using email / password
signUpPOST: async function (input) {
if (originalImplementation.signUpPOST === undefined) {
throw new Error("Should never come here");
signUp: async function (input) {
let resp = await originalImplementation.signUp(input);
if (resp.status === "OK" && resp.user.loginMethods.length === 1) {
/*
* This is called during the sign up API for email password login,
* but before calling the createNewSession function.
* We override the recipe function as shown here,
* and then set the relevant context only if it's a new user.
*/
input.userContext.isSignUp = true;
}

// by default, the userContext object is {},
// we change it to {isSignUp: true}, since this is the
// sign up API, and this will tell the createNewSession function
// (being called inside originalImplementation.signUpPOST)
// to not create a new session in case userContext.isSignUp === true
input.userContext.isSignUp = true;
return originalImplementation.signUpPOST(input);
return resp;
},
}
}
@@ -219,7 +219,8 @@ SuperTokens.init({
antiCsrfToken: undefined,
refreshToken: undefined,
}),
getTenantId: () => "public"
getTenantId: () => "public",
getRecipeUserId: () => SuperTokens.convertToRecipeUserId(""),
};
}
return originalImplementation.createNewSession(input);
Loading

0 comments on commit c0fb0e7

Please sign in to comment.