From 7e044a9d0d7af92246ebdcbdcc7f1c44d5e31be1 Mon Sep 17 00:00:00 2001 From: NkxxkN Date: Tue, 16 Feb 2021 15:21:27 +0100 Subject: [PATCH 01/74] add-supertokens-to-authentication.md --- docs/authentication.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/authentication.md b/docs/authentication.md index 591cddb311d9459..23f002acfedac0c 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -130,6 +130,18 @@ Both of these libraries support either authentication pattern. If you're interes - [with-passport](https://github.com/vercel/next.js/tree/canary/examples/with-passport) - [with-passport-and-next-connect](https://github.com/vercel/next.js/tree/canary/examples/with-passport-and-next-connect) + +### SuperTokens + +
+ Examples + +
+ +[SuperTokens](https://supertokens.io) is an open source secure authentication system with many features such as credentials login, email verification, reset password flows, and third party logins. + ### Firebase
From e2909935e17df5313bee3748314573131f54799b Mon Sep 17 00:00:00 2001 From: NkxxkN Date: Thu, 18 Feb 2021 10:19:07 +0100 Subject: [PATCH 02/74] bump supertokens deps --- docs/authentication.md | 1 - examples/with-supertokens/package.json | 4 ++-- examples/with-supertokens/pages/_app.js | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/authentication.md b/docs/authentication.md index 23f002acfedac0c..b91576cc378031b 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -130,7 +130,6 @@ Both of these libraries support either authentication pattern. If you're interes - [with-passport](https://github.com/vercel/next.js/tree/canary/examples/with-passport) - [with-passport-and-next-connect](https://github.com/vercel/next.js/tree/canary/examples/with-passport-and-next-connect) - ### SuperTokens
diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index cf74d7385382965..0e226b1e0ed9993 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,8 +11,8 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.5.1", - "supertokens-node": "^3.4.0" + "supertokens-auth-react": "^0.6.0", + "supertokens-node": "^4.0.0" }, "license": "MIT" } diff --git a/examples/with-supertokens/pages/_app.js b/examples/with-supertokens/pages/_app.js index 7b3539765523977..323b6d6959016db 100644 --- a/examples/with-supertokens/pages/_app.js +++ b/examples/with-supertokens/pages/_app.js @@ -16,6 +16,7 @@ const apiBasePath = '/api/auth/' // Client Side configs. if (typeof window !== 'undefined') { SuperTokensReact.init({ + useReactRouterDom: false, appInfo: { appName: 'SuperTokens Demo App', websiteDomain, From 0fecb526b03f9852381691f036f941216c81d8ba Mon Sep 17 00:00:00 2001 From: NkxxkN Date: Mon, 1 Mar 2021 16:35:56 +0100 Subject: [PATCH 03/74] update SuperTokens Auth doc --- docs/authentication.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/authentication.md b/docs/authentication.md index b91576cc378031b..8088904d61915f9 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -130,17 +130,6 @@ Both of these libraries support either authentication pattern. If you're interes - [with-passport](https://github.com/vercel/next.js/tree/canary/examples/with-passport) - [with-passport-and-next-connect](https://github.com/vercel/next.js/tree/canary/examples/with-passport-and-next-connect) -### SuperTokens - -
- Examples - -
- -[SuperTokens](https://supertokens.io) is an open source secure authentication system with many features such as credentials login, email verification, reset password flows, and third party logins. - ### Firebase
@@ -200,6 +189,18 @@ You can either use [FirebaseUI](https://github.com/firebase/firebaseui-web-react [Userbase](https://userbase.com/) supports the static generation pattern for authentication. It's open source and allows for a high level of security with end-to-end encryption. You can learn more about it in their [official site](https://userbase.com/). +### SuperTokens + +
+ Examples + +
+ +[SuperTokens](https://supertokens.io) is a highly customisable, open source auth split into modules so that you use only what you need. +SuperTokens currently supports credentials login, email verification, reset password flows and third party logins. + ## Related For more information on what to do next, we recommend the following sections: From 49caedd60636079fdf505ebebed6919f2b046821 Mon Sep 17 00:00:00 2001 From: NkxxkN Date: Mon, 1 Mar 2021 16:47:14 +0100 Subject: [PATCH 04/74] Update docs/authentication.md Co-authored-by: Lee Robinson --- docs/authentication.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/authentication.md b/docs/authentication.md index 16c3eb95326ce55..69cf7ccace17806 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -199,7 +199,7 @@ You can either use [FirebaseUI](https://github.com/firebase/firebaseui-web-react
[SuperTokens](https://supertokens.io) is a highly customisable, open source auth split into modules so that you use only what you need. -SuperTokens currently supports credentials login, email verification, reset password flows and third party logins. +SuperTokens currently supports credentials login, email verification, password reset flows, and third-party logins. ## Related From a00f6a515d875fe62e73ce7f8113a19521fdc7db Mon Sep 17 00:00:00 2001 From: NkxxkN Date: Mon, 1 Mar 2021 16:47:43 +0100 Subject: [PATCH 05/74] Update docs/authentication.md Co-authored-by: Lee Robinson --- docs/authentication.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/authentication.md b/docs/authentication.md index 69cf7ccace17806..430661cbabc384f 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -198,7 +198,7 @@ You can either use [FirebaseUI](https://github.com/firebase/firebaseui-web-react
-[SuperTokens](https://supertokens.io) is a highly customisable, open source auth split into modules so that you use only what you need. +[SuperTokens](https://supertokens.io) is a highly customizable, open-source solution split into modules (so you only use what you need). SuperTokens currently supports credentials login, email verification, password reset flows, and third-party logins. ## Related From fa05b787c44472c4aa6d7f7fc58ae99c8e3474d8 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Tue, 6 Apr 2021 14:48:02 +0530 Subject: [PATCH 06/74] updates supertokens dependency and optimises for serverless execution --- examples/with-supertokens/package.json | 6 +++--- examples/with-supertokens/pages/_app.js | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 0e226b1e0ed9993..fecc2622ffab22b 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,8 +11,8 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.6.0", - "supertokens-node": "^4.0.0" + "supertokens-auth-react": "^0.8", + "supertokens-node": "^4.2.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/examples/with-supertokens/pages/_app.js b/examples/with-supertokens/pages/_app.js index 323b6d6959016db..8c70ed29cc06de4 100644 --- a/examples/with-supertokens/pages/_app.js +++ b/examples/with-supertokens/pages/_app.js @@ -45,6 +45,7 @@ if (typeof window !== 'undefined') { apiBasePath, }, recipeList: [EmailPasswordNode.init(), SessionNode.init()], + isInServerlessEnv: true }) } From feab6fbfd9bca7e246269771d22592fc8093155f Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Tue, 6 Apr 2021 15:18:34 +0530 Subject: [PATCH 07/74] runs prettier-fix --- examples/with-supertokens/package.json | 2 +- examples/with-supertokens/pages/_app.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index fecc2622ffab22b..c03781dfa7f7037 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -15,4 +15,4 @@ "supertokens-node": "^4.2.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/examples/with-supertokens/pages/_app.js b/examples/with-supertokens/pages/_app.js index 190c8dbf1895b06..5b533c7fff766ad 100644 --- a/examples/with-supertokens/pages/_app.js +++ b/examples/with-supertokens/pages/_app.js @@ -70,7 +70,7 @@ if (typeof window !== 'undefined') { }), SessionNode.init(), ], - isInServerlessEnv: true + isInServerlessEnv: true, }) } From 7a5082350e44f52774765daffe24d4c6a0b3d455 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Wed, 7 Apr 2021 23:33:43 +0530 Subject: [PATCH 08/74] adds supertokens to 'Bring Your Own Database' section as well --- docs/authentication.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/authentication.md b/docs/authentication.md index 7ca2bbab29ee49d..0837747feae6723 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -127,6 +127,8 @@ Both of these libraries support either authentication pattern. If you're interes - [with-passport](https://github.com/vercel/next.js/tree/canary/examples/with-passport) - [with-passport-and-next-connect](https://github.com/vercel/next.js/tree/canary/examples/with-passport-and-next-connect) +- If you want a self hosted version of some of the services listed below, please checkout [SuperTokens](/docs/authentication#supertokens). + ### Firebase
From b44c159096f157d5e51a9cf77ee575690109d68e Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Thu, 8 Apr 2021 12:50:54 +0530 Subject: [PATCH 09/74] does not show home page if not logged in --- examples/with-supertokens/pages/index.js | 101 ++++++++++++----------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/examples/with-supertokens/pages/index.js b/examples/with-supertokens/pages/index.js index 656020b815e6eba..d7718c8e2c84649 100644 --- a/examples/with-supertokens/pages/index.js +++ b/examples/with-supertokens/pages/index.js @@ -15,6 +15,14 @@ const ThirdPartyEmailPasswordAuthNoSSR = dynamic( ) export default function Home() { + return ( + + + + ) +} + +function ProtectedPage() { async function logoutClicked() { await ThirdPartyEmailPassword.signOut() window.location.href = '/auth' @@ -37,68 +45,66 @@ export default function Home() {

Welcome to Next.js!

- -

- You are authenticated with SuperTokens! -

+

+ You are authenticated with SuperTokens! +

+
-
- SIGN OUT -
+ SIGN OUT
+
+
-
- FETCH USER API -
+ FETCH USER API
- +
-
[SuperTokens](https://supertokens.io) is a highly customizable, open-source solution split into modules (so you only use what you need). -SuperTokens currently supports credentials login, email verification, password reset flows, and third-party logins. +SuperTokens currently supports credentials login, email verification, password reset flows, third-party logins, and cookie based sessions with rotating refresh tokens. ## Related From 80e72e9e5979decfd2b08eef8c3b83fa12aa7e6c Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Fri, 9 Apr 2021 11:52:22 +0530 Subject: [PATCH 16/74] adds placeholder secrets so that the UI loads on first run --- examples/with-supertokens/pages/supertokensConfig.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/with-supertokens/pages/supertokensConfig.js b/examples/with-supertokens/pages/supertokensConfig.js index 37e88b14260af83..720cc8d247049ce 100644 --- a/examples/with-supertokens/pages/supertokensConfig.js +++ b/examples/with-supertokens/pages/supertokensConfig.js @@ -28,16 +28,16 @@ export let backendConfig = () => { ThirdPartyEmailPasswordNode.init({ providers: [ ThirdPartyEmailPasswordNode.Google({ - clientSecret: process.env.GOOGLE_CLIENT_SECRET, - clientId: process.env.GOOGLE_CLIENT_ID, + clientSecret: process.env.GOOGLE_CLIENT_SECRET || 'PLACEHOLDER', + clientId: process.env.GOOGLE_CLIENT_ID || 'PLACEHOLDER', }), ThirdPartyEmailPasswordNode.Github({ - clientSecret: process.env.GITHUB_CLIENT_SECRET, - clientId: process.env.GITHUB_CLIENT_ID, + clientSecret: process.env.GITHUB_CLIENT_SECRET || 'PLACEHOLDER', + clientId: process.env.GITHUB_CLIENT_ID || 'PLACEHOLDER', }), ThirdPartyEmailPasswordNode.Facebook({ - clientSecret: process.env.FACEBOOK_CLIENT_SECRET, - clientId: process.env.FACEBOOK_CLIENT_ID, + clientSecret: process.env.FACEBOOK_CLIENT_SECRET || 'PLACEHOLDER', + clientId: process.env.FACEBOOK_CLIENT_ID || 'PLACEHOLDER', }), ], }), From bbf27a2ffc48e2a363ed87b4ceaa320fe96a3bef Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Fri, 9 Apr 2021 12:37:31 +0530 Subject: [PATCH 17/74] changes to readme --- examples/with-supertokens/README.md | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/examples/with-supertokens/README.md b/examples/with-supertokens/README.md index 21f31494e9b7be8..f8c8232b192f4f1 100644 --- a/examples/with-supertokens/README.md +++ b/examples/with-supertokens/README.md @@ -2,10 +2,6 @@ This is a simple set up for applications protected by SuperTokens. -The SuperTokens back end configurations are in `supertokens.js`. - -The SuperTokens front end configurations are in `pages/_app.js`. - ## Deploy your own Deploy the example using [Vercel](https://vercel.com): @@ -24,11 +20,13 @@ yarn create next-app --example with-supertokens with-supertokens-app ## Configuration -Create a `.env.local` file and copy the content of `.env.local.example` into it: +- Create a `.env.local` file and copy the content of `.env.local.example` into it: -```bash -cp .env.local.example .env.local -``` + ```bash + cp .env.local.example .env.local + ``` + +- Fill in the values for your social login secrets ## Deploy on Vercel @@ -42,6 +40,4 @@ To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [ ## Notes -Take a look at [SuperTokens documentation](https://supertokens.io/docs/emailpassword/introduction) to configure SuperTokens for your project. - -Especially, you will want to replace the use of the demo SuperTokens core with your own SuperTokens core instance. See https://supertokens.io/docs/emailpassword/quick-setup/supertokens-core/overview. +Take a look at [SuperTokens documentation](https://supertokens.io/docs/community/introduction). From 52e423b3dbe814f3e00fc94646cc8912164983bb Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Fri, 16 Apr 2021 23:02:06 +0530 Subject: [PATCH 18/74] updates version of supertokens frontend and backend SDK, and a few other fixes --- .../{pages => config}/supertokensConfig.js | 0 examples/with-supertokens/package.json | 4 ++-- examples/with-supertokens/pages/_app.js | 11 ++++++++--- .../with-supertokens/pages/api/auth/[[...path]].js | 7 +++++-- examples/with-supertokens/pages/api/user.js | 2 +- examples/with-supertokens/pages/auth/[[...path]].js | 3 ++- 6 files changed, 18 insertions(+), 9 deletions(-) rename examples/with-supertokens/{pages => config}/supertokensConfig.js (100%) diff --git a/examples/with-supertokens/pages/supertokensConfig.js b/examples/with-supertokens/config/supertokensConfig.js similarity index 100% rename from examples/with-supertokens/pages/supertokensConfig.js rename to examples/with-supertokens/config/supertokensConfig.js diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index c03781dfa7f7037..b529f3023465abe 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,8 +11,8 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.8", - "supertokens-node": "^4.2.0" + "supertokens-auth-react": "^0.9.0", + "supertokens-node": "^4.3.0" }, "license": "MIT" } diff --git a/examples/with-supertokens/pages/_app.js b/examples/with-supertokens/pages/_app.js index e8f6d9f75d71d28..509412d98d03273 100644 --- a/examples/with-supertokens/pages/_app.js +++ b/examples/with-supertokens/pages/_app.js @@ -2,9 +2,10 @@ import '../styles/globals.css' import React from 'react' import { useEffect } from 'react' import SuperTokensReact from 'supertokens-auth-react' -import * as SuperTokensConfig from './supertokensConfig' +import * as SuperTokensConfig from '../config/supertokensConfig' import Session from 'supertokens-auth-react/recipe/session' import SuperTokensNode from 'supertokens-node' +import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword' if (typeof window !== 'undefined') { SuperTokensReact.init(SuperTokensConfig.frontendConfig()) @@ -16,8 +17,12 @@ function MyApp({ Component, pageProps }) { useEffect(() => { async function doRefresh() { if (pageProps.fromSupertokens === 'needs-refresh') { - await Session.attemptRefreshingSession() - location.reload() + if (await Session.attemptRefreshingSession()) { + location.reload() + } else { + // user has been logged out + redirectToAuth() + } } } doRefresh() diff --git a/examples/with-supertokens/pages/api/auth/[[...path]].js b/examples/with-supertokens/pages/api/auth/[[...path]].js index a7695444e21968f..0e540a66524bcab 100644 --- a/examples/with-supertokens/pages/api/auth/[[...path]].js +++ b/examples/with-supertokens/pages/api/auth/[[...path]].js @@ -1,16 +1,19 @@ // Next.js API route support: https://nextjs.org/docs/api-routes/introduction import { superTokensNextWrapper } from 'supertokens-node/nextjs' import supertokens from 'supertokens-node' -import * as SuperTokensConfig from '../../supertokensConfig' +import * as SuperTokensConfig from '../../../config/supertokensConfig' supertokens.init(SuperTokensConfig.backendConfig()) export default async function superTokens(req, res) { - return await superTokensNextWrapper( + await superTokensNextWrapper( async (next) => { await supertokens.middleware()(req, res, next) }, req, res ) + if (!res.writableEnded) { + res.status(404).send('Not found') + } } diff --git a/examples/with-supertokens/pages/api/user.js b/examples/with-supertokens/pages/api/user.js index 2ad2c6e84c04030..926af6e18723194 100644 --- a/examples/with-supertokens/pages/api/user.js +++ b/examples/with-supertokens/pages/api/user.js @@ -1,7 +1,7 @@ import { superTokensNextWrapper } from 'supertokens-node/nextjs' import { verifySession } from 'supertokens-node/recipe/session' import supertokens from 'supertokens-node' -import * as SuperTokensConfig from '../supertokensConfig' +import * as SuperTokensConfig from '../../config/supertokensConfig' supertokens.init(SuperTokensConfig.backendConfig()) diff --git a/examples/with-supertokens/pages/auth/[[...path]].js b/examples/with-supertokens/pages/auth/[[...path]].js index 45f0ae793e6342d..cf32c2826c05067 100644 --- a/examples/with-supertokens/pages/auth/[[...path]].js +++ b/examples/with-supertokens/pages/auth/[[...path]].js @@ -3,6 +3,7 @@ import React, { useEffect } from 'react' import styles from '../../styles/Home.module.css' import dynamic from 'next/dynamic' import SuperTokens from 'supertokens-auth-react' +import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword' const SuperTokensComponentNoSSR = dynamic( new Promise((res) => res(SuperTokens.getRoutingComponent)), @@ -12,7 +13,7 @@ const SuperTokensComponentNoSSR = dynamic( export default function Auth() { useEffect(() => { if (SuperTokens.canHandleRoute() === false) { - window.location.href = '/' + redirectToAuth() } }, []) From c88554b88848bab4bb815506740203e07eb49bb4 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Tue, 20 Apr 2021 09:11:05 +0530 Subject: [PATCH 19/74] Update docs/authentication.md Co-authored-by: Lee Robinson --- docs/authentication.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/authentication.md b/docs/authentication.md index 970b7b62f1605ae..00e15c1e43797ed 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -127,8 +127,6 @@ Both of these libraries support either authentication pattern. If you're interes - [with-passport](https://github.com/vercel/next.js/tree/canary/examples/with-passport) - [with-passport-and-next-connect](https://github.com/vercel/next.js/tree/canary/examples/with-passport-and-next-connect) -- [SuperTokens](/docs/authentication#supertokens) (more info below) also allows you to store data within your own database. - ### Firebase
From 5c7bf789a770a84e632eeea23af5c9722234bb1e Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Wed, 21 Apr 2021 10:56:01 +0530 Subject: [PATCH 20/74] updates to readme for supertokens example --- examples/with-supertokens/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/with-supertokens/README.md b/examples/with-supertokens/README.md index f8c8232b192f4f1..e9e856ae58c6326 100644 --- a/examples/with-supertokens/README.md +++ b/examples/with-supertokens/README.md @@ -10,7 +10,7 @@ Deploy the example using [Vercel](https://vercel.com): ## How to use -Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: +- Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: ```bash npx create-next-app --example with-supertokens with-supertokens-app @@ -18,8 +18,14 @@ npx create-next-app --example with-supertokens with-supertokens-app yarn create next-app --example with-supertokens with-supertokens-app ``` +- Run `yarn install` + +- Run `npm run dev` to start the application on `http://localhost:3000`. + ## Configuration +> Until you do this, social login will not work. But you can still try out email password sign up / in. + - Create a `.env.local` file and copy the content of `.env.local.example` into it: ```bash From 472ce2ce25bf2afdbcc0245c9a0d9955faf43de9 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Thu, 29 Apr 2021 00:16:39 +0530 Subject: [PATCH 21/74] updates version of dependency --- examples/with-supertokens/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index b529f3023465abe..512d16200cc322d 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,8 +11,8 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.9.0", - "supertokens-node": "^4.3.0" + "supertokens-auth-react": "^0.10.0", + "supertokens-node": "^4.4.1" }, "license": "MIT" } From d2288cc57dd6cbe43c7736cbe6bf93195e9cf8dc Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Mon, 3 May 2021 17:51:48 +0530 Subject: [PATCH 22/74] updates dependency version --- examples/with-supertokens/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 512d16200cc322d..c48b987ec8decaf 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,8 +11,8 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.10.0", - "supertokens-node": "^4.4.1" + "supertokens-auth-react": "^0.11.0", + "supertokens-node": "^5.0.0" }, "license": "MIT" } From 4f8a48c05f288061907b87f336a97d325f14873b Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Wed, 5 May 2021 12:40:04 +0530 Subject: [PATCH 23/74] updates to dependencies --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index c48b987ec8decaf..ac40d1262d1a431 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,7 +11,7 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.11.0", + "supertokens-auth-react": "^0.12.0", "supertokens-node": "^5.0.0" }, "license": "MIT" From 8976fa2dcaf6d3db8614640c0fd56bf5812ef6e3 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Wed, 5 May 2021 12:40:43 +0530 Subject: [PATCH 24/74] removes unnecessary config on frontend --- examples/with-supertokens/config/supertokensConfig.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/with-supertokens/config/supertokensConfig.js b/examples/with-supertokens/config/supertokensConfig.js index 720cc8d247049ce..b6509c888f13ed6 100644 --- a/examples/with-supertokens/config/supertokensConfig.js +++ b/examples/with-supertokens/config/supertokensConfig.js @@ -49,7 +49,6 @@ export let backendConfig = () => { export let frontendConfig = () => { return { - useReactRouterDom: false, appInfo, recipeList: [ ThirdPartyEmailPasswordReact.init({ From 652211cf40e39ba8c49bd93d4ced6482159ef8f5 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Wed, 12 May 2021 11:58:11 +0530 Subject: [PATCH 25/74] changes how redirection is done post signout --- examples/with-supertokens/pages/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/with-supertokens/pages/index.js b/examples/with-supertokens/pages/index.js index 00284df70e94cff..befe0d5d5cb9429 100644 --- a/examples/with-supertokens/pages/index.js +++ b/examples/with-supertokens/pages/index.js @@ -42,13 +42,17 @@ export default function Home(props) { function ProtectedPage({ userId }) { async function logoutClicked() { await ThirdPartyEmailPassword.signOut() - window.location.href = '/auth' + ThirdPartyEmailPassword.redirectToAuth() } async function fetchUserData() { const res = await fetch('/api/user') - const json = await res.json() - alert(JSON.stringify(json)) + if (res.status === 401) { + ThirdPartyEmailPassword.redirectToAuth() + } else { + const json = await res.json() + alert(JSON.stringify(json)) + } } return ( From 538d794fe4f033315e69c6e52a42fb0140016fa7 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Thu, 13 May 2021 20:10:47 +0530 Subject: [PATCH 26/74] update to dependency --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index ac40d1262d1a431..b98f6ca22612f95 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,7 +11,7 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.12.0", + "supertokens-auth-react": "^0.13.0", "supertokens-node": "^5.0.0" }, "license": "MIT" From 0769b2490ef55f3520bf60568e220c83383e2fd0 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Thu, 17 Jun 2021 12:26:08 +0530 Subject: [PATCH 27/74] updates examples --- examples/with-supertokens/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index b98f6ca22612f95..cf8723d16e3dd89 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,8 +11,8 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.13.0", - "supertokens-node": "^5.0.0" + "supertokens-auth-react": "^0.14.0", + "supertokens-node": "^6.0.0" }, "license": "MIT" } From 381c26fd487115442c3c931c706ce800ebe58ae0 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Sun, 11 Jul 2021 14:39:15 +0530 Subject: [PATCH 28/74] updates code to use for new package --- examples/with-supertokens/package.json | 2 +- examples/with-supertokens/pages/index.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index cf8723d16e3dd89..45fcf0c5f876c01 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,7 +11,7 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.14.0", + "supertokens-auth-react": "github:supertokens/supertokens-auth-react#0.15", "supertokens-node": "^6.0.0" }, "license": "MIT" diff --git a/examples/with-supertokens/pages/index.js b/examples/with-supertokens/pages/index.js index befe0d5d5cb9429..e1ce8fbd1a6fbca 100644 --- a/examples/with-supertokens/pages/index.js +++ b/examples/with-supertokens/pages/index.js @@ -47,9 +47,7 @@ function ProtectedPage({ userId }) { async function fetchUserData() { const res = await fetch('/api/user') - if (res.status === 401) { - ThirdPartyEmailPassword.redirectToAuth() - } else { + if (res.status === 200) { const json = await res.json() alert(JSON.stringify(json)) } From 8aef52c4e987b76a0914c74bbb6b4b383ff607e0 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Sun, 11 Jul 2021 16:53:31 +0530 Subject: [PATCH 29/74] updates dependencies --- examples/with-supertokens/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 45fcf0c5f876c01..bc9a7a2f9c0438c 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -14,5 +14,8 @@ "supertokens-auth-react": "github:supertokens/supertokens-auth-react#0.15", "supertokens-node": "^6.0.0" }, - "license": "MIT" + "license": "MIT", + "devDependencies": { + "eslint-config-next": "11.0.1" + } } From 3c8889179597c7d7f5d0902d96dac17facc92ee7 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Sun, 11 Jul 2021 19:06:33 +0530 Subject: [PATCH 30/74] updates auth-react package --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index bc9a7a2f9c0438c..1037e8665c2664c 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,7 +11,7 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "github:supertokens/supertokens-auth-react#0.15", + "supertokens-auth-react": "^0.15.0", "supertokens-node": "^6.0.0" }, "license": "MIT", From 0bfff12a6c13fa4db31e97c3e7eef96ef80f78f5 Mon Sep 17 00:00:00 2001 From: Bhumil Sarvaiya Date: Thu, 26 Aug 2021 15:14:34 +0530 Subject: [PATCH 31/74] with-supertokens example updated to use supertokens-node v7 --- examples/with-supertokens/config/supertokensConfig.js | 1 + examples/with-supertokens/package.json | 2 +- examples/with-supertokens/pages/api/auth/[[...path]].js | 3 ++- examples/with-supertokens/pages/api/user.js | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/with-supertokens/config/supertokensConfig.js b/examples/with-supertokens/config/supertokensConfig.js index b6509c888f13ed6..345291965bdcd71 100644 --- a/examples/with-supertokens/config/supertokensConfig.js +++ b/examples/with-supertokens/config/supertokensConfig.js @@ -20,6 +20,7 @@ let appInfo = { export let backendConfig = () => { return { + framework: "express", supertokens: { connectionURI: 'https://try.supertokens.io', }, diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 1037e8665c2664c..a30ef0458565500 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -12,7 +12,7 @@ "react": "17.0.1", "react-dom": "17.0.1", "supertokens-auth-react": "^0.15.0", - "supertokens-node": "^6.0.0" + "supertokens-node": "^7.0.0" }, "license": "MIT", "devDependencies": { diff --git a/examples/with-supertokens/pages/api/auth/[[...path]].js b/examples/with-supertokens/pages/api/auth/[[...path]].js index 0e540a66524bcab..323c685218e981f 100644 --- a/examples/with-supertokens/pages/api/auth/[[...path]].js +++ b/examples/with-supertokens/pages/api/auth/[[...path]].js @@ -1,6 +1,7 @@ // Next.js API route support: https://nextjs.org/docs/api-routes/introduction import { superTokensNextWrapper } from 'supertokens-node/nextjs' import supertokens from 'supertokens-node' +import { middleware } from 'supertokens-node/framework/express' import * as SuperTokensConfig from '../../../config/supertokensConfig' supertokens.init(SuperTokensConfig.backendConfig()) @@ -8,7 +9,7 @@ supertokens.init(SuperTokensConfig.backendConfig()) export default async function superTokens(req, res) { await superTokensNextWrapper( async (next) => { - await supertokens.middleware()(req, res, next) + await middleware()(req, res, next) }, req, res diff --git a/examples/with-supertokens/pages/api/user.js b/examples/with-supertokens/pages/api/user.js index 926af6e18723194..104aba0751008d5 100644 --- a/examples/with-supertokens/pages/api/user.js +++ b/examples/with-supertokens/pages/api/user.js @@ -1,5 +1,5 @@ import { superTokensNextWrapper } from 'supertokens-node/nextjs' -import { verifySession } from 'supertokens-node/recipe/session' +import { verifySession } from 'supertokens-node/recipe/session/framework/express' import supertokens from 'supertokens-node' import * as SuperTokensConfig from '../../config/supertokensConfig' From 8aeaa0e8eb4cbdf32876af32a8b4dc3fb2d750b7 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Thu, 26 Aug 2021 19:13:59 +0530 Subject: [PATCH 32/74] updates dependency --- examples/with-supertokens/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index a30ef0458565500..9a4bcc84cc6ed97 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -12,10 +12,10 @@ "react": "17.0.1", "react-dom": "17.0.1", "supertokens-auth-react": "^0.15.0", - "supertokens-node": "^7.0.0" + "supertokens-node": "github:supertokens/supertokens-node#7.0" }, "license": "MIT", "devDependencies": { "eslint-config-next": "11.0.1" } -} +} \ No newline at end of file From 33475d51200c1d81b4884b5edb2ae7eab94fb562 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 8 Sep 2021 17:43:15 +0530 Subject: [PATCH 33/74] updates supertokens-node version --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 9a4bcc84cc6ed97..3fd3e4148f2b6dd 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -12,7 +12,7 @@ "react": "17.0.1", "react-dom": "17.0.1", "supertokens-auth-react": "^0.15.0", - "supertokens-node": "github:supertokens/supertokens-node#7.0" + "supertokens-node": "^7.0.0" }, "license": "MIT", "devDependencies": { From f1bf8dc6edb406df795f7dbf6b4a3efadfe30627 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Wed, 8 Sep 2021 19:39:06 +0530 Subject: [PATCH 34/74] Update examples/with-supertokens/package.json Co-authored-by: Lee Robinson --- examples/with-supertokens/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 775aeef554c70c1..8efaaebffb2e4d0 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -12,7 +12,6 @@ "supertokens-auth-react": "^0.15.0", "supertokens-node": "^7.0.0" }, - "license": "MIT", "devDependencies": { "eslint-config-next": "11.0.1" } From fbedc66c234979693f951ca1a84746019e8d9aa5 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Thu, 9 Sep 2021 18:45:45 +0530 Subject: [PATCH 35/74] updates based on check-examples.sh script --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 8efaaebffb2e4d0..0a6dcef7fbc52e9 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -15,4 +15,4 @@ "devDependencies": { "eslint-config-next": "11.0.1" } -} \ No newline at end of file +} From 9a3b04aebb2d427c2f321fdad1285042b7724d42 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Thu, 9 Sep 2021 18:57:03 +0530 Subject: [PATCH 36/74] linter fix --- examples/with-supertokens/config/supertokensConfig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/config/supertokensConfig.js b/examples/with-supertokens/config/supertokensConfig.js index 345291965bdcd71..ffb4e216a263dd6 100644 --- a/examples/with-supertokens/config/supertokensConfig.js +++ b/examples/with-supertokens/config/supertokensConfig.js @@ -20,7 +20,7 @@ let appInfo = { export let backendConfig = () => { return { - framework: "express", + framework: 'express', supertokens: { connectionURI: 'https://try.supertokens.io', }, From a74b64a2b47d93d2e5f2f07134e3c8b8318f9fe0 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Fri, 1 Oct 2021 17:51:57 +0530 Subject: [PATCH 37/74] updates supertokens-auth-react dependency version --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 0a6dcef7fbc52e9..1c28325a1b1afa5 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -9,7 +9,7 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.15.0", + "supertokens-auth-react": "^0.16.0", "supertokens-node": "^7.0.0" }, "devDependencies": { From a16c4b54dab471b3a387a149acf07af2fdb4c740 Mon Sep 17 00:00:00 2001 From: jscyo Date: Wed, 13 Oct 2021 16:28:14 +0530 Subject: [PATCH 38/74] adds development OAuth key to example --- examples/with-supertokens/README.md | 22 ------------------- .../config/supertokensConfig.js | 20 +++++++++-------- examples/with-supertokens/package.json | 2 +- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/examples/with-supertokens/README.md b/examples/with-supertokens/README.md index e9e856ae58c6326..5fdc76a45bd8fe0 100644 --- a/examples/with-supertokens/README.md +++ b/examples/with-supertokens/README.md @@ -22,28 +22,6 @@ yarn create next-app --example with-supertokens with-supertokens-app - Run `npm run dev` to start the application on `http://localhost:3000`. -## Configuration - -> Until you do this, social login will not work. But you can still try out email password sign up / in. - -- Create a `.env.local` file and copy the content of `.env.local.example` into it: - - ```bash - cp .env.local.example .env.local - ``` - -- Fill in the values for your social login secrets - -## Deploy on Vercel - -You can deploy this app to the cloud with [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). - -### Deploy Your Local Project - -To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example). - -**Important**: When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file. - ## Notes Take a look at [SuperTokens documentation](https://supertokens.io/docs/community/introduction). diff --git a/examples/with-supertokens/config/supertokensConfig.js b/examples/with-supertokens/config/supertokensConfig.js index ffb4e216a263dd6..d56d0447ee9e6d9 100644 --- a/examples/with-supertokens/config/supertokensConfig.js +++ b/examples/with-supertokens/config/supertokensConfig.js @@ -28,18 +28,21 @@ export let backendConfig = () => { recipeList: [ ThirdPartyEmailPasswordNode.init({ providers: [ + // We have provided you with development keys which you can use for testing. + // IMPORTANT: Please replace them with your own OAuth keys for production use. ThirdPartyEmailPasswordNode.Google({ - clientSecret: process.env.GOOGLE_CLIENT_SECRET || 'PLACEHOLDER', - clientId: process.env.GOOGLE_CLIENT_ID || 'PLACEHOLDER', + clientId: + '1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com', + clientSecret: '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', }), ThirdPartyEmailPasswordNode.Github({ - clientSecret: process.env.GITHUB_CLIENT_SECRET || 'PLACEHOLDER', - clientId: process.env.GITHUB_CLIENT_ID || 'PLACEHOLDER', - }), - ThirdPartyEmailPasswordNode.Facebook({ - clientSecret: process.env.FACEBOOK_CLIENT_SECRET || 'PLACEHOLDER', - clientId: process.env.FACEBOOK_CLIENT_ID || 'PLACEHOLDER', + clientId: '467101b197249757c71f', + clientSecret: 'e97051221f4b6426e8fe8d51486396703012f5bd', }), + // ThirdPartyEmailPasswordNode.Facebook({ + // clientSecret: process.env.FACEBOOK_CLIENT_SECRET || 'PLACEHOLDER', + // clientId: process.env.FACEBOOK_CLIENT_ID || 'PLACEHOLDER', + // }), ], }), SessionNode.init(), @@ -60,7 +63,6 @@ export let frontendConfig = () => { providers: [ ThirdPartyEmailPasswordReact.Google.init(), ThirdPartyEmailPasswordReact.Github.init(), - ThirdPartyEmailPasswordReact.Facebook.init(), ], }, }), diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 1c28325a1b1afa5..ef0fa9244509f71 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -10,7 +10,7 @@ "react": "17.0.1", "react-dom": "17.0.1", "supertokens-auth-react": "^0.16.0", - "supertokens-node": "^7.0.0" + "supertokens-node": "^7.3.0" }, "devDependencies": { "eslint-config-next": "11.0.1" From d767c93e08a8e606cfe34ba48db0eac6bbc5ab78 Mon Sep 17 00:00:00 2001 From: jscyo Date: Wed, 13 Oct 2021 17:10:51 +0530 Subject: [PATCH 39/74] removes section from README --- examples/with-supertokens/README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/examples/with-supertokens/README.md b/examples/with-supertokens/README.md index 5fdc76a45bd8fe0..dc143596c6ff84f 100644 --- a/examples/with-supertokens/README.md +++ b/examples/with-supertokens/README.md @@ -2,12 +2,6 @@ This is a simple set up for applications protected by SuperTokens. -## Deploy your own - -Deploy the example using [Vercel](https://vercel.com): - -[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-supertokens&project-name=with-supertokens&repository-name=with-supertokens) - ## How to use - Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: From c06c01dbd6f4c195ee3cc076a5b4b4537eb11ab1 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 13 Oct 2021 18:12:31 +0530 Subject: [PATCH 40/74] removes unnecessary file --- examples/with-supertokens/.env.local.example | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 examples/with-supertokens/.env.local.example diff --git a/examples/with-supertokens/.env.local.example b/examples/with-supertokens/.env.local.example deleted file mode 100644 index 6757361556f3441..000000000000000 --- a/examples/with-supertokens/.env.local.example +++ /dev/null @@ -1,17 +0,0 @@ -# Public Environment variables that can be used in the browser. -NEXT_PUBLIC_APP_URL="http://localhost:3000" - -# Secret environment variables only available to Node.js -APP_URL="http://localhost:3000" - -## Github -GITHUB_CLIENT_ID= -GITHUB_CLIENT_SECRET= - -## Google -GOOGLE_CLIENT_ID= -GOOGLE_CLIENT_SECRET= - -## Facebook -FACEBOOK_CLIENT_ID= -FACEBOOK_CLIENT_SECRET= From 26efb9bdb44f1a2a535c4694c60e40a7c3add59e Mon Sep 17 00:00:00 2001 From: Rishabh Date: Fri, 22 Oct 2021 13:24:44 +0530 Subject: [PATCH 41/74] updates dependency versions --- examples/with-supertokens/package.json | 4 ++-- examples/with-supertokens/pages/api/user.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index ef0fa9244509f71..b8b60ba71617581 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -9,8 +9,8 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.16.0", - "supertokens-node": "^7.3.0" + "supertokens-auth-react": "^0.17.0", + "supertokens-node": "^8.0.0" }, "devDependencies": { "eslint-config-next": "11.0.1" diff --git a/examples/with-supertokens/pages/api/user.js b/examples/with-supertokens/pages/api/user.js index c40664705eabbd5..2d47b0c6834db15 100644 --- a/examples/with-supertokens/pages/api/user.js +++ b/examples/with-supertokens/pages/api/user.js @@ -18,6 +18,6 @@ export default async function user(req, res) { note: 'Fetch any data from your application for authenticated user after using verifySession middleware', userId: req.session.getUserId(), sessionHandle: req.session.getHandle(), - userDataInJWT: req.session.getJWTPayload(), + accessTokenPayload: req.session.getAccessTokenPayload(), }) } From 31380c720c09eb099828b8e1d755e237061a2103 Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Sat, 30 Oct 2021 01:40:12 +0200 Subject: [PATCH 42/74] with-supertokens: reduced bundle size by removing node lib from bundle Linting fix --- examples/with-supertokens/config/appInfo.js | 15 ++++++++ ...{supertokensConfig.js => backendConfig.js} | 38 +------------------ .../with-supertokens/config/frontendConfig.js | 23 +++++++++++ examples/with-supertokens/next.config.js | 16 ++++++++ examples/with-supertokens/pages/_app.js | 11 ++++-- .../pages/api/auth/[[...path]].js | 4 +- examples/with-supertokens/pages/api/user.js | 4 +- 7 files changed, 67 insertions(+), 44 deletions(-) create mode 100644 examples/with-supertokens/config/appInfo.js rename examples/with-supertokens/config/{supertokensConfig.js => backendConfig.js} (59%) create mode 100644 examples/with-supertokens/config/frontendConfig.js create mode 100644 examples/with-supertokens/next.config.js diff --git a/examples/with-supertokens/config/appInfo.js b/examples/with-supertokens/config/appInfo.js new file mode 100644 index 000000000000000..081b4c89d991e57 --- /dev/null +++ b/examples/with-supertokens/config/appInfo.js @@ -0,0 +1,15 @@ +const port = process.env.APP_PORT || 3000 + +const apiBasePath = '/api/auth/' + +export const websiteDomain = + process.env.APP_URL || + process.env.NEXT_PUBLIC_APP_URL || + `http://localhost:${port}` + +export const appInfo = { + appName: 'SuperTokens Demo App', + websiteDomain, + apiDomain: websiteDomain, + apiBasePath, +} diff --git a/examples/with-supertokens/config/supertokensConfig.js b/examples/with-supertokens/config/backendConfig.js similarity index 59% rename from examples/with-supertokens/config/supertokensConfig.js rename to examples/with-supertokens/config/backendConfig.js index d56d0447ee9e6d9..20b91ff544ac5ed 100644 --- a/examples/with-supertokens/config/supertokensConfig.js +++ b/examples/with-supertokens/config/backendConfig.js @@ -1,22 +1,6 @@ import ThirdPartyEmailPasswordNode from 'supertokens-node/recipe/thirdpartyemailpassword' import SessionNode from 'supertokens-node/recipe/session' - -import ThirdPartyEmailPasswordReact from 'supertokens-auth-react/recipe/thirdpartyemailpassword' -import SessionReact from 'supertokens-auth-react/recipe/session' - -const port = process.env.APP_PORT || 3000 -const websiteDomain = - process.env.APP_URL || - process.env.NEXT_PUBLIC_APP_URL || - `http://localhost:${port}` -const apiBasePath = '/api/auth/' - -let appInfo = { - appName: 'SuperTokens Demo App', - websiteDomain, - apiDomain: websiteDomain, - apiBasePath, -} +import { appInfo } from './appInfo' export let backendConfig = () => { return { @@ -50,23 +34,3 @@ export let backendConfig = () => { isInServerlessEnv: true, } } - -export let frontendConfig = () => { - return { - appInfo, - recipeList: [ - ThirdPartyEmailPasswordReact.init({ - emailVerificationFeature: { - mode: 'REQUIRED', - }, - signInAndUpFeature: { - providers: [ - ThirdPartyEmailPasswordReact.Google.init(), - ThirdPartyEmailPasswordReact.Github.init(), - ], - }, - }), - SessionReact.init(), - ], - } -} diff --git a/examples/with-supertokens/config/frontendConfig.js b/examples/with-supertokens/config/frontendConfig.js new file mode 100644 index 000000000000000..7ddfe54ed931eda --- /dev/null +++ b/examples/with-supertokens/config/frontendConfig.js @@ -0,0 +1,23 @@ +import ThirdPartyEmailPasswordReact from 'supertokens-auth-react/recipe/thirdpartyemailpassword' +import SessionReact from 'supertokens-auth-react/recipe/session' +import { appInfo } from './appInfo' + +export let frontendConfig = () => { + return { + appInfo, + recipeList: [ + ThirdPartyEmailPasswordReact.init({ + emailVerificationFeature: { + mode: 'REQUIRED', + }, + signInAndUpFeature: { + providers: [ + ThirdPartyEmailPasswordReact.Google.init(), + ThirdPartyEmailPasswordReact.Github.init(), + ], + }, + }), + SessionReact.init(), + ], + } +} diff --git a/examples/with-supertokens/next.config.js b/examples/with-supertokens/next.config.js new file mode 100644 index 000000000000000..6f1d8f1e2360407 --- /dev/null +++ b/examples/with-supertokens/next.config.js @@ -0,0 +1,16 @@ +const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') + +module.exports = { + webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => { + if (true) { + config.plugins.push( + new BundleAnalyzerPlugin({ + analyzerMode: 'server', + analyzerPort: isServer ? 8888 : 8889, + openAnalyzer: true, + }) + ) + } + return config + }, +} diff --git a/examples/with-supertokens/pages/_app.js b/examples/with-supertokens/pages/_app.js index 509412d98d03273..c44a9b2670e9ee5 100644 --- a/examples/with-supertokens/pages/_app.js +++ b/examples/with-supertokens/pages/_app.js @@ -2,15 +2,20 @@ import '../styles/globals.css' import React from 'react' import { useEffect } from 'react' import SuperTokensReact from 'supertokens-auth-react' -import * as SuperTokensConfig from '../config/supertokensConfig' +import * as SuperTokensConfig from '../config/frontendConfig' import Session from 'supertokens-auth-react/recipe/session' -import SuperTokensNode from 'supertokens-node' import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword' +async function initNode() { + const supertokensNode = await import('supertokens-node') + const { backendConfig } = await import('../config/backendConfig') + supertokensNode.init(backendConfig()) +} + if (typeof window !== 'undefined') { SuperTokensReact.init(SuperTokensConfig.frontendConfig()) } else { - SuperTokensNode.init(SuperTokensConfig.backendConfig()) + initNode().catch(console.error) } function MyApp({ Component, pageProps }) { diff --git a/examples/with-supertokens/pages/api/auth/[[...path]].js b/examples/with-supertokens/pages/api/auth/[[...path]].js index 323c685218e981f..903812d578257dd 100644 --- a/examples/with-supertokens/pages/api/auth/[[...path]].js +++ b/examples/with-supertokens/pages/api/auth/[[...path]].js @@ -2,9 +2,9 @@ import { superTokensNextWrapper } from 'supertokens-node/nextjs' import supertokens from 'supertokens-node' import { middleware } from 'supertokens-node/framework/express' -import * as SuperTokensConfig from '../../../config/supertokensConfig' +import { backendConfig } from '../../../config/backendConfig' -supertokens.init(SuperTokensConfig.backendConfig()) +supertokens.init(backendConfig()) export default async function superTokens(req, res) { await superTokensNextWrapper( diff --git a/examples/with-supertokens/pages/api/user.js b/examples/with-supertokens/pages/api/user.js index 2d47b0c6834db15..f76a139d170b8bf 100644 --- a/examples/with-supertokens/pages/api/user.js +++ b/examples/with-supertokens/pages/api/user.js @@ -1,9 +1,9 @@ import { superTokensNextWrapper } from 'supertokens-node/nextjs' import { verifySession } from 'supertokens-node/recipe/session/framework/express' import supertokens from 'supertokens-node' -import * as SuperTokensConfig from '../../config/supertokensConfig' +import { backendConfig } from '../../config/backendConfig' -supertokens.init(SuperTokensConfig.backendConfig()) +supertokens.init(backendConfig()) export default async function user(req, res) { await superTokensNextWrapper( From d2986e429e8c3794064e35450a3f3331c9a8a130 Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Wed, 3 Nov 2021 22:56:33 +0100 Subject: [PATCH 43/74] Removed accidentally added config file --- examples/with-supertokens/next.config.js | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 examples/with-supertokens/next.config.js diff --git a/examples/with-supertokens/next.config.js b/examples/with-supertokens/next.config.js deleted file mode 100644 index 6f1d8f1e2360407..000000000000000 --- a/examples/with-supertokens/next.config.js +++ /dev/null @@ -1,16 +0,0 @@ -const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') - -module.exports = { - webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => { - if (true) { - config.plugins.push( - new BundleAnalyzerPlugin({ - analyzerMode: 'server', - analyzerPort: isServer ? 8888 : 8889, - openAnalyzer: true, - }) - ) - } - return config - }, -} From c7804969c197a386d59314d9ae99560cf81eba26 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 9 Nov 2021 17:18:54 +0530 Subject: [PATCH 44/74] adds sign in with apple --- examples/with-supertokens/config/backendConfig.js | 9 +++++++++ examples/with-supertokens/config/frontendConfig.js | 1 + examples/with-supertokens/package.json | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/with-supertokens/config/backendConfig.js b/examples/with-supertokens/config/backendConfig.js index 20b91ff544ac5ed..2552956f8a091d5 100644 --- a/examples/with-supertokens/config/backendConfig.js +++ b/examples/with-supertokens/config/backendConfig.js @@ -23,6 +23,15 @@ export let backendConfig = () => { clientId: '467101b197249757c71f', clientSecret: 'e97051221f4b6426e8fe8d51486396703012f5bd', }), + ThirdPartyEmailPasswordNode.Apple({ + clientId: '4398792-io.supertokens.example.service', + clientSecret: { + keyId: '7M48Y4RYDL', + privateKey: + '-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----', + teamId: 'YWQCXGJRJL', + }, + }), // ThirdPartyEmailPasswordNode.Facebook({ // clientSecret: process.env.FACEBOOK_CLIENT_SECRET || 'PLACEHOLDER', // clientId: process.env.FACEBOOK_CLIENT_ID || 'PLACEHOLDER', diff --git a/examples/with-supertokens/config/frontendConfig.js b/examples/with-supertokens/config/frontendConfig.js index 7ddfe54ed931eda..365deafb01c3925 100644 --- a/examples/with-supertokens/config/frontendConfig.js +++ b/examples/with-supertokens/config/frontendConfig.js @@ -14,6 +14,7 @@ export let frontendConfig = () => { providers: [ ThirdPartyEmailPasswordReact.Google.init(), ThirdPartyEmailPasswordReact.Github.init(), + ThirdPartyEmailPasswordReact.Apple.init(), ], }, }), diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index b8b60ba71617581..74f8e063c6c1dc6 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -10,7 +10,7 @@ "react": "17.0.1", "react-dom": "17.0.1", "supertokens-auth-react": "^0.17.0", - "supertokens-node": "^8.0.0" + "supertokens-node": "^8.1.0" }, "devDependencies": { "eslint-config-next": "11.0.1" From cf5939b07d2662f54d06dae3696044368f706d2b Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 9 Nov 2021 21:25:29 +0530 Subject: [PATCH 45/74] extracted oauth keys to .env file --- examples/with-supertokens/.env | 14 ++++++++++++ examples/with-supertokens/README.md | 3 ++- .../with-supertokens/config/backendConfig.js | 22 +++++++------------ 3 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 examples/with-supertokens/.env diff --git a/examples/with-supertokens/.env b/examples/with-supertokens/.env new file mode 100644 index 000000000000000..9a88ce3f1b01846 --- /dev/null +++ b/examples/with-supertokens/.env @@ -0,0 +1,14 @@ +# These are all working development keys. +# IMPORTANT: You can use them during development, but for production use, +# make sure to change them to keys issued for your app. + +GOOGLE_CLIENT_ID=1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com +GOOGLE_CLIENT_SECRET=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 + +GITHUB_CLIENT_ID=467101b197249757c71f +GITHUB_CLIENT_SECRET=e97051221f4b6426e8fe8d51486396703012f5bd + +APPLE_CLIENT_ID=4398792-io.supertokens.example.service +APPLE_KEY_ID=7M48Y4RYDL +APPLE_TEAM_ID=YWQCXGJRJL +APPLE_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY----- \ No newline at end of file diff --git a/examples/with-supertokens/README.md b/examples/with-supertokens/README.md index dc143596c6ff84f..31f3c4660c62063 100644 --- a/examples/with-supertokens/README.md +++ b/examples/with-supertokens/README.md @@ -18,4 +18,5 @@ yarn create next-app --example with-supertokens with-supertokens-app ## Notes -Take a look at [SuperTokens documentation](https://supertokens.io/docs/community/introduction). +- Take a look at [SuperTokens documentation](https://supertokens.io/docs/community/introduction). +- We have provided development OAuth keys for the various in build third party providers in the `.env` file. Feel free to use them for development purposes, but **please create your own keys for production use**. diff --git a/examples/with-supertokens/config/backendConfig.js b/examples/with-supertokens/config/backendConfig.js index 2552956f8a091d5..64b10c7b62e8de2 100644 --- a/examples/with-supertokens/config/backendConfig.js +++ b/examples/with-supertokens/config/backendConfig.js @@ -15,27 +15,21 @@ export let backendConfig = () => { // We have provided you with development keys which you can use for testing. // IMPORTANT: Please replace them with your own OAuth keys for production use. ThirdPartyEmailPasswordNode.Google({ - clientId: - '1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com', - clientSecret: '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', + clientId: process.env.GOOGLE_CLIENT_ID, + clientSecret: process.env.GOOGLE_CLIENT_SECRET, }), ThirdPartyEmailPasswordNode.Github({ - clientId: '467101b197249757c71f', - clientSecret: 'e97051221f4b6426e8fe8d51486396703012f5bd', + clientId: process.env.GITHUB_CLIENT_ID, + clientSecret: process.env.GITHUB_CLIENT_SECRET, }), ThirdPartyEmailPasswordNode.Apple({ - clientId: '4398792-io.supertokens.example.service', + clientId: process.env.APPLE_CLIENT_ID, clientSecret: { - keyId: '7M48Y4RYDL', - privateKey: - '-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----', - teamId: 'YWQCXGJRJL', + keyId: process.env.APPLE_KEY_ID, + privateKey: process.env.APPLE_PRIVATE_KEY.replace(/\\n/g, '\n'), + teamId: process.env.APPLE_TEAM_ID, }, }), - // ThirdPartyEmailPasswordNode.Facebook({ - // clientSecret: process.env.FACEBOOK_CLIENT_SECRET || 'PLACEHOLDER', - // clientId: process.env.FACEBOOK_CLIENT_ID || 'PLACEHOLDER', - // }), ], }), SessionNode.init(), From ce0970c845e238048fad50b8dd95c153413c65d5 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 14 Dec 2021 14:59:44 +0530 Subject: [PATCH 46/74] fixes node init issue race condition --- examples/with-supertokens/.babelrc | 5 +++++ examples/with-supertokens/pages/_app.js | 8 -------- examples/with-supertokens/pages/index.js | 4 ++++ 3 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 examples/with-supertokens/.babelrc diff --git a/examples/with-supertokens/.babelrc b/examples/with-supertokens/.babelrc new file mode 100644 index 000000000000000..964220ed01b6802 --- /dev/null +++ b/examples/with-supertokens/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + "next/babel" + ] +} \ No newline at end of file diff --git a/examples/with-supertokens/pages/_app.js b/examples/with-supertokens/pages/_app.js index c44a9b2670e9ee5..d596135dc05c0c3 100644 --- a/examples/with-supertokens/pages/_app.js +++ b/examples/with-supertokens/pages/_app.js @@ -6,16 +6,8 @@ import * as SuperTokensConfig from '../config/frontendConfig' import Session from 'supertokens-auth-react/recipe/session' import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword' -async function initNode() { - const supertokensNode = await import('supertokens-node') - const { backendConfig } = await import('../config/backendConfig') - supertokensNode.init(backendConfig()) -} - if (typeof window !== 'undefined') { SuperTokensReact.init(SuperTokensConfig.frontendConfig()) -} else { - initNode().catch(console.error) } function MyApp({ Component, pageProps }) { diff --git a/examples/with-supertokens/pages/index.js b/examples/with-supertokens/pages/index.js index e1ce8fbd1a6fbca..0629fa410da25bb 100644 --- a/examples/with-supertokens/pages/index.js +++ b/examples/with-supertokens/pages/index.js @@ -3,6 +3,8 @@ import Head from 'next/head' import styles from '../styles/Home.module.css' import ThirdPartyEmailPassword from 'supertokens-auth-react/recipe/thirdpartyemailpassword' import dynamic from 'next/dynamic' +import supertokensNode from 'supertokens-node' +import { backendConfig } from '../config/backendConfig' import Session from 'supertokens-node/recipe/session' const ThirdPartyEmailPasswordAuthNoSSR = dynamic( @@ -13,6 +15,8 @@ const ThirdPartyEmailPasswordAuthNoSSR = dynamic( ) export async function getServerSideProps(context) { + // this runs on the backend, so we must call init on supertokens-node SDK + supertokensNode.init(backendConfig()) let session try { session = await Session.getSession(context.req, context.res) From 3b3a01e26fcbaa2caa90da169f7ac4944135b117 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 14 Dec 2021 17:00:12 +0530 Subject: [PATCH 47/74] removes unnecessary file --- examples/with-supertokens/.babelrc | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 examples/with-supertokens/.babelrc diff --git a/examples/with-supertokens/.babelrc b/examples/with-supertokens/.babelrc deleted file mode 100644 index 964220ed01b6802..000000000000000 --- a/examples/with-supertokens/.babelrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "presets": [ - "next/babel" - ] -} \ No newline at end of file From ce09b5ebf667b751b573f98e9c4d7bbd0adcc911 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Mon, 17 Jan 2022 16:41:25 +0530 Subject: [PATCH 48/74] updates supertokens-auth-react dependency --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 74f8e063c6c1dc6..829c98de05ff7bb 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -9,7 +9,7 @@ "next": "latest", "react": "17.0.1", "react-dom": "17.0.1", - "supertokens-auth-react": "^0.17.0", + "supertokens-auth-react": "^0.18.0", "supertokens-node": "^8.1.0" }, "devDependencies": { From 46f0212e013a55c0aa42000543a2141a002daaa4 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 22 Feb 2022 15:40:58 +0530 Subject: [PATCH 49/74] updates superttokens-node dependency --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 829c98de05ff7bb..7a58108be0f6b00 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -10,7 +10,7 @@ "react": "17.0.1", "react-dom": "17.0.1", "supertokens-auth-react": "^0.18.0", - "supertokens-node": "^8.1.0" + "supertokens-node": "^9.0.0" }, "devDependencies": { "eslint-config-next": "11.0.1" From 72888f106f2722811b56e95310cdd256bdbdde6e Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 22 Feb 2022 16:38:47 +0530 Subject: [PATCH 50/74] adds a cap to react dependency --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index a6e2971a557e93f..094a3cf24a7ad17 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -7,7 +7,7 @@ }, "dependencies": { "next": "latest", - "react": "17.0.1", + "react": "^17.0.1", "react-dom": "^17.0.1", "supertokens-auth-react": "^0.18.0", "supertokens-node": "^9.0.0" From 82a171f141f58826f353ffca23bb781cc3f6bdcc Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 22 Feb 2022 16:41:09 +0530 Subject: [PATCH 51/74] updates eslint-config-next version --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 094a3cf24a7ad17..8f9ff08ca216ac2 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -13,6 +13,6 @@ "supertokens-node": "^9.0.0" }, "devDependencies": { - "eslint-config-next": "11.0.1" + "eslint-config-next": "^12.1.0" } } From 44152f126341407c94363889d1b9da583a3a2a02 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 22 Feb 2022 16:46:16 +0530 Subject: [PATCH 52/74] removes unnecessary dev dependency --- examples/with-supertokens/package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 8f9ff08ca216ac2..5f4e2067c308b11 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -11,8 +11,5 @@ "react-dom": "^17.0.1", "supertokens-auth-react": "^0.18.0", "supertokens-node": "^9.0.0" - }, - "devDependencies": { - "eslint-config-next": "^12.1.0" } } From 7e09d8bc8885360c1fe16ac23bf6e6642c4cfd5b Mon Sep 17 00:00:00 2001 From: Rishabh Date: Thu, 3 Mar 2022 20:50:47 +0530 Subject: [PATCH 53/74] updates to latest version of supertokens-auth-react SDK --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 5f4e2067c308b11..ae96a6debfd8c9d 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -9,7 +9,7 @@ "next": "latest", "react": "^17.0.1", "react-dom": "^17.0.1", - "supertokens-auth-react": "^0.18.0", + "supertokens-auth-react": "^0.19.0", "supertokens-node": "^9.0.0" } } From d8978d758bfd55dd28d38b4a34573bf45291a5c4 Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Thu, 7 Apr 2022 12:02:13 +0200 Subject: [PATCH 54/74] Updated nextjs in supertokens example --- examples/with-supertokens/.gitignore | 6 ++---- examples/with-supertokens/next.config.js | 6 ++++++ examples/with-supertokens/package.json | 15 ++++++++++----- 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 examples/with-supertokens/next.config.js diff --git a/examples/with-supertokens/.gitignore b/examples/with-supertokens/.gitignore index 1437c53f70bc211..55175ef867e0b00 100644 --- a/examples/with-supertokens/.gitignore +++ b/examples/with-supertokens/.gitignore @@ -23,12 +23,10 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +.pnpm-debug.log* # local env files -.env.local -.env.development.local -.env.test.local -.env.production.local +.env*.local # vercel .vercel diff --git a/examples/with-supertokens/next.config.js b/examples/with-supertokens/next.config.js new file mode 100644 index 000000000000000..a843cbee09afaad --- /dev/null +++ b/examples/with-supertokens/next.config.js @@ -0,0 +1,6 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + reactStrictMode: true, +} + +module.exports = nextConfig diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index ae96a6debfd8c9d..efca78ecf9216a2 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -3,13 +3,18 @@ "scripts": { "dev": "next dev", "build": "next build", - "start": "next start" + "start": "next start", + "lint": "next lint" }, "dependencies": { "next": "latest", - "react": "^17.0.1", - "react-dom": "^17.0.1", - "supertokens-auth-react": "^0.19.0", - "supertokens-node": "^9.0.0" + "react": "18.0.0", + "react-dom": "18.0.0", + "supertokens-auth-react": "^0.20.1", + "supertokens-node": "^9.1.1" + }, + "devDependencies": { + "eslint": "8.12.0", + "eslint-config-next": "12.1.4" } } From 3834a2a05f87beb7df8105fe18ec60a83f2e21b0 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Thu, 7 Apr 2022 16:24:46 +0530 Subject: [PATCH 55/74] Update examples/with-supertokens/package.json --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index efca78ecf9216a2..d20a68923f49fd8 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -8,7 +8,7 @@ }, "dependencies": { "next": "latest", - "react": "18.0.0", + "react": "^18.0.0", "react-dom": "18.0.0", "supertokens-auth-react": "^0.20.1", "supertokens-node": "^9.1.1" From a0cfddb6c358d48e13e33fa63956a5ca7d09b3f8 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Thu, 7 Apr 2022 16:24:51 +0530 Subject: [PATCH 56/74] Update examples/with-supertokens/package.json --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index d20a68923f49fd8..9ab0fff1796840e 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -9,7 +9,7 @@ "dependencies": { "next": "latest", "react": "^18.0.0", - "react-dom": "18.0.0", + "react-dom": "^18.0.0", "supertokens-auth-react": "^0.20.1", "supertokens-node": "^9.1.1" }, From f4508e7fa53eeb8f1792d9f29219e3cb0d6c85b8 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Fri, 8 Apr 2022 14:03:16 +0530 Subject: [PATCH 57/74] Update package.json --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 9ab0fff1796840e..be484f8c3449656 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -10,7 +10,7 @@ "next": "latest", "react": "^18.0.0", "react-dom": "^18.0.0", - "supertokens-auth-react": "^0.20.1", + "supertokens-auth-react": "^0.20.2", "supertokens-node": "^9.1.1" }, "devDependencies": { From 66c16d7d2c7baf96cf691ef3a27c58c37ad0564e Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Mon, 11 Apr 2022 15:17:27 +0530 Subject: [PATCH 58/74] Update examples/with-supertokens/package.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Balázs Orbán --- examples/with-supertokens/package.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index be484f8c3449656..6039bd7437ac531 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -12,9 +12,5 @@ "react-dom": "^18.0.0", "supertokens-auth-react": "^0.20.2", "supertokens-node": "^9.1.1" - }, - "devDependencies": { - "eslint": "8.12.0", - "eslint-config-next": "12.1.4" } } From 55bd67c68ba3ae66253821b4f7515e19eaa05196 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Mon, 11 Apr 2022 15:17:36 +0530 Subject: [PATCH 59/74] Update examples/with-supertokens/package.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Balázs Orbán --- examples/with-supertokens/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 6039bd7437ac531..2644c54301a0aec 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -3,8 +3,7 @@ "scripts": { "dev": "next dev", "build": "next build", - "start": "next start", - "lint": "next lint" + "start": "next start" }, "dependencies": { "next": "latest", From c6fd5e1b7beaa62caf2a83c911db4719af481eb9 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Sat, 14 May 2022 13:08:14 +0530 Subject: [PATCH 60/74] updates to supertokens-auth-react version --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 2644c54301a0aec..7e63692184f1320 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -9,7 +9,7 @@ "next": "latest", "react": "^18.0.0", "react-dom": "^18.0.0", - "supertokens-auth-react": "^0.20.2", + "supertokens-auth-react": "^0.21.2", "supertokens-node": "^9.1.1" } } From a6a687d6d661eaa537e84c45524729233ea458cc Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Mon, 4 Jul 2022 03:40:16 +0200 Subject: [PATCH 61/74] feat: update&improve ssr in with-supertokens --- examples/with-supertokens/package.json | 3 +- examples/with-supertokens/pages/_app.js | 9 +- .../pages/auth/[[...path]].js | 22 +- examples/with-supertokens/pages/index.js | 197 +++++++++--------- 4 files changed, 116 insertions(+), 115 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 7e63692184f1320..75cbd534270abe5 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -7,9 +7,10 @@ }, "dependencies": { "next": "latest", + "prettier": "^2.7.1", "react": "^18.0.0", "react-dom": "^18.0.0", - "supertokens-auth-react": "^0.21.2", + "supertokens-auth-react": "github:supertokens/supertokens-auth-react#next-breaking-change", "supertokens-node": "^9.1.1" } } diff --git a/examples/with-supertokens/pages/_app.js b/examples/with-supertokens/pages/_app.js index d596135dc05c0c3..8eec10de744f863 100644 --- a/examples/with-supertokens/pages/_app.js +++ b/examples/with-supertokens/pages/_app.js @@ -1,7 +1,7 @@ import '../styles/globals.css' import React from 'react' import { useEffect } from 'react' -import SuperTokensReact from 'supertokens-auth-react' +import SuperTokensReact, { SuperTokensWrapper } from 'supertokens-auth-react' import * as SuperTokensConfig from '../config/frontendConfig' import Session from 'supertokens-auth-react/recipe/session' import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword' @@ -27,7 +27,12 @@ function MyApp({ Component, pageProps }) { if (pageProps.fromSupertokens === 'needs-refresh') { return null } - return + + return ( + + + + ) } export default MyApp diff --git a/examples/with-supertokens/pages/auth/[[...path]].js b/examples/with-supertokens/pages/auth/[[...path]].js index cf32c2826c05067..fe62dfbc278ad81 100644 --- a/examples/with-supertokens/pages/auth/[[...path]].js +++ b/examples/with-supertokens/pages/auth/[[...path]].js @@ -2,7 +2,7 @@ import Head from 'next/head' import React, { useEffect } from 'react' import styles from '../../styles/Home.module.css' import dynamic from 'next/dynamic' -import SuperTokens from 'supertokens-auth-react' +import SuperTokens, { SuperTokensWrapper } from 'supertokens-auth-react' import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword' const SuperTokensComponentNoSSR = dynamic( @@ -18,15 +18,17 @@ export default function Auth() { }, []) return ( -
- - SuperTokens 💫 - - + +
+ + SuperTokens 💫 + + -
- -
-
+
+ +
+
+ ) } diff --git a/examples/with-supertokens/pages/index.js b/examples/with-supertokens/pages/index.js index 0599974ed0faf14..f017ca1e8971184 100644 --- a/examples/with-supertokens/pages/index.js +++ b/examples/with-supertokens/pages/index.js @@ -1,19 +1,13 @@ import React from 'react' import Head from 'next/head' import styles from '../styles/Home.module.css' -import ThirdPartyEmailPassword from 'supertokens-auth-react/recipe/thirdpartyemailpassword' -import dynamic from 'next/dynamic' +import ThirdPartyEmailPassword, { + ThirdPartyEmailPasswordAuth, +} from 'supertokens-auth-react/recipe/thirdpartyemailpassword' import supertokensNode from 'supertokens-node' import { backendConfig } from '../config/backendConfig' import Session from 'supertokens-node/recipe/session' -const ThirdPartyEmailPasswordAuthNoSSR = dynamic( - new Promise((res) => - res(ThirdPartyEmailPassword.ThirdPartyEmailPasswordAuth) - ), - { ssr: false } -) - export async function getServerSideProps(context) { // this runs on the backend, so we must call init on supertokens-node SDK supertokensNode.init(backendConfig()) @@ -37,9 +31,30 @@ export async function getServerSideProps(context) { export default function Home(props) { return ( - - - +
+ + SuperTokens 💫 + + +
+

+ Welcome to Next.js! +

+ + + +
+ +
) } @@ -58,117 +73,95 @@ function ProtectedPage({ userId }) { } return ( -
- - SuperTokens 💫 - - - -
-

- Welcome to Next.js! -

-

- You are authenticated with SuperTokens! (UserID: {userId}) -

+ <> +

+ You are authenticated with SuperTokens! (UserID: {userId}) +

+
-
- SIGN OUT -
+ SIGN OUT
+
+
-
- FETCH USER API -
+ FETCH USER API
+
-
- -
+ + ) } From f3472752b1da1d817757e415330247f5ce2500cf Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Mon, 4 Jul 2022 09:45:43 +0200 Subject: [PATCH 62/74] refactor: implement review feedback --- .../pages/auth/[[...path]].js | 22 +++++++++---------- examples/with-supertokens/pages/index.js | 17 +++++++++++++- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/examples/with-supertokens/pages/auth/[[...path]].js b/examples/with-supertokens/pages/auth/[[...path]].js index fe62dfbc278ad81..cf32c2826c05067 100644 --- a/examples/with-supertokens/pages/auth/[[...path]].js +++ b/examples/with-supertokens/pages/auth/[[...path]].js @@ -2,7 +2,7 @@ import Head from 'next/head' import React, { useEffect } from 'react' import styles from '../../styles/Home.module.css' import dynamic from 'next/dynamic' -import SuperTokens, { SuperTokensWrapper } from 'supertokens-auth-react' +import SuperTokens from 'supertokens-auth-react' import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword' const SuperTokensComponentNoSSR = dynamic( @@ -18,17 +18,15 @@ export default function Auth() { }, []) return ( - -
- - SuperTokens 💫 - - +
+ + SuperTokens 💫 + + -
- -
-
- +
+ +
+
) } diff --git a/examples/with-supertokens/pages/index.js b/examples/with-supertokens/pages/index.js index f017ca1e8971184..68f4e21cc45616f 100644 --- a/examples/with-supertokens/pages/index.js +++ b/examples/with-supertokens/pages/index.js @@ -7,6 +7,7 @@ import ThirdPartyEmailPassword, { import supertokensNode from 'supertokens-node' import { backendConfig } from '../config/backendConfig' import Session from 'supertokens-node/recipe/session' +import { useSessionContext } from 'supertokens-auth-react/recipe/session' export async function getServerSideProps(context) { // this runs on the backend, so we must call init on supertokens-node SDK @@ -40,6 +41,7 @@ export default function Home(props) {

Welcome to Next.js!

+ @@ -59,6 +61,8 @@ export default function Home(props) { } function ProtectedPage({ userId }) { + const session = useSessionContext() + async function logoutClicked() { await ThirdPartyEmailPassword.signOut() ThirdPartyEmailPassword.redirectToAuth() @@ -72,12 +76,23 @@ function ProtectedPage({ userId }) { } } + if (session.loading === true) { + // It should never come here, since this is wrapped by ThirdPartyEmailPasswordAuth with requireAuth=true + return null + } + return ( <>

- You are authenticated with SuperTokens! (UserID: {userId}) + You are authenticated with SuperTokens!

+

+ UserId: {session.userId}
(from SSR: {userId}) +

+

+ Access token payload: {JSON.stringify(session.accessTokenPayload)} +

Date: Mon, 4 Jul 2022 09:51:16 +0200 Subject: [PATCH 63/74] refactor: moved everything into ProtectedPage to make Auth component usage clearer --- examples/with-supertokens/pages/index.js | 197 +++++++++++------------ 1 file changed, 98 insertions(+), 99 deletions(-) diff --git a/examples/with-supertokens/pages/index.js b/examples/with-supertokens/pages/index.js index 68f4e21cc45616f..587c4d8e38c50fe 100644 --- a/examples/with-supertokens/pages/index.js +++ b/examples/with-supertokens/pages/index.js @@ -32,31 +32,9 @@ export async function getServerSideProps(context) { export default function Home(props) { return ( -
- - SuperTokens 💫 - - -
-

- Welcome to Next.js! -

- - - - -
- -
+ + + ) } @@ -82,101 +60,122 @@ function ProtectedPage({ userId }) { } return ( - <> -

- You are authenticated with SuperTokens! -

+
+ + SuperTokens 💫 + + +
+

+ Welcome to Next.js! +

+

+ You are authenticated with SuperTokens! +

-

- UserId: {session.userId}
(from SSR: {userId}) -

-

- Access token payload: {JSON.stringify(session.accessTokenPayload)} -

-
+

+ UserId: {session.userId}
(from SSR: {userId}) +

+

+ Access token payload: {JSON.stringify(session.accessTokenPayload)} +

- SIGN OUT +
+ SIGN OUT +
-
-
- FETCH USER API +
+ FETCH USER API +
-
-
+
- + +
) } From 30ecda5c8f31340d9e5e2fe35c9dba5ea09b2b2a Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Mon, 4 Jul 2022 13:25:10 +0200 Subject: [PATCH 64/74] refactor: implement review feedback --- examples/with-supertokens/pages/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/with-supertokens/pages/index.js b/examples/with-supertokens/pages/index.js index 587c4d8e38c50fe..41202162c3b4637 100644 --- a/examples/with-supertokens/pages/index.js +++ b/examples/with-supertokens/pages/index.js @@ -32,7 +32,7 @@ export async function getServerSideProps(context) { export default function Home(props) { return ( - + ) @@ -55,7 +55,6 @@ function ProtectedPage({ userId }) { } if (session.loading === true) { - // It should never come here, since this is wrapped by ThirdPartyEmailPasswordAuth with requireAuth=true return null } From 703f86809d614bf594e6b0a8ac9c8458433a66a6 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Wed, 6 Jul 2022 15:20:44 +0530 Subject: [PATCH 65/74] updates dependency version and uses nextjs router for navigation --- examples/with-supertokens/config/frontendConfig.js | 13 +++++++++++++ examples/with-supertokens/package.json | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/with-supertokens/config/frontendConfig.js b/examples/with-supertokens/config/frontendConfig.js index 365deafb01c3925..92036971ee75a7b 100644 --- a/examples/with-supertokens/config/frontendConfig.js +++ b/examples/with-supertokens/config/frontendConfig.js @@ -1,6 +1,7 @@ import ThirdPartyEmailPasswordReact from 'supertokens-auth-react/recipe/thirdpartyemailpassword' import SessionReact from 'supertokens-auth-react/recipe/session' import { appInfo } from './appInfo' +import Router from 'next/router' export let frontendConfig = () => { return { @@ -20,5 +21,17 @@ export let frontendConfig = () => { }), SessionReact.init(), ], + // this is so that the SDK uses the next router for navigation + windowHandler: (oI) => { + return { + ...oI, + location: { + ...oI.location, + setHref: (href) => { + Router.push(href) + }, + }, + } + }, } } diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 75cbd534270abe5..22c4769880b174e 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -10,7 +10,7 @@ "prettier": "^2.7.1", "react": "^18.0.0", "react-dom": "^18.0.0", - "supertokens-auth-react": "github:supertokens/supertokens-auth-react#next-breaking-change", - "supertokens-node": "^9.1.1" + "supertokens-auth-react": "^0.24.0", + "supertokens-node": "^11.0.0" } } From 94708bd2972fd66fa85397c26eadfd872467d8b6 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Wed, 6 Jul 2022 15:25:25 +0530 Subject: [PATCH 66/74] removes prettier dendency in with-supertokens example app --- examples/with-supertokens/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 22c4769880b174e..c53c43acc94ff9a 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -7,7 +7,6 @@ }, "dependencies": { "next": "latest", - "prettier": "^2.7.1", "react": "^18.0.0", "react-dom": "^18.0.0", "supertokens-auth-react": "^0.24.0", From 8f59d2447dc1932a7a4b30ac831cb82d6e59e144 Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Wed, 7 Sep 2022 00:35:34 +0200 Subject: [PATCH 67/74] docs(examples): updated supertokens example --- .../with-supertokens/config/backendConfig.js | 4 ++++ .../with-supertokens/config/frontendConfig.js | 5 ++--- examples/with-supertokens/pages/_app.js | 6 ++++-- examples/with-supertokens/pages/index.js | 21 ++++++++++++------- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/examples/with-supertokens/config/backendConfig.js b/examples/with-supertokens/config/backendConfig.js index 64b10c7b62e8de2..79eee592be1560b 100644 --- a/examples/with-supertokens/config/backendConfig.js +++ b/examples/with-supertokens/config/backendConfig.js @@ -1,4 +1,5 @@ import ThirdPartyEmailPasswordNode from 'supertokens-node/recipe/thirdpartyemailpassword' +import EmailVerificationNode from 'supertokens-node/recipe/emailverification' import SessionNode from 'supertokens-node/recipe/session' import { appInfo } from './appInfo' @@ -10,6 +11,9 @@ export let backendConfig = () => { }, appInfo, recipeList: [ + EmailVerificationNode.init({ + mode: 'REQUIRED', + }), ThirdPartyEmailPasswordNode.init({ providers: [ // We have provided you with development keys which you can use for testing. diff --git a/examples/with-supertokens/config/frontendConfig.js b/examples/with-supertokens/config/frontendConfig.js index 92036971ee75a7b..95c6e274ac70ca8 100644 --- a/examples/with-supertokens/config/frontendConfig.js +++ b/examples/with-supertokens/config/frontendConfig.js @@ -1,4 +1,5 @@ import ThirdPartyEmailPasswordReact from 'supertokens-auth-react/recipe/thirdpartyemailpassword' +import EmailVerificationReact from 'supertokens-auth-react/recipe/emailverification' import SessionReact from 'supertokens-auth-react/recipe/session' import { appInfo } from './appInfo' import Router from 'next/router' @@ -7,10 +8,8 @@ export let frontendConfig = () => { return { appInfo, recipeList: [ + EmailVerificationReact.init(), ThirdPartyEmailPasswordReact.init({ - emailVerificationFeature: { - mode: 'REQUIRED', - }, signInAndUpFeature: { providers: [ ThirdPartyEmailPasswordReact.Google.init(), diff --git a/examples/with-supertokens/pages/_app.js b/examples/with-supertokens/pages/_app.js index 8eec10de744f863..58cbc56685418cb 100644 --- a/examples/with-supertokens/pages/_app.js +++ b/examples/with-supertokens/pages/_app.js @@ -1,10 +1,12 @@ import '../styles/globals.css' import React from 'react' import { useEffect } from 'react' -import SuperTokensReact, { SuperTokensWrapper } from 'supertokens-auth-react' +import SuperTokensReact, { + SuperTokensWrapper, + redirectToAuth, +} from 'supertokens-auth-react' import * as SuperTokensConfig from '../config/frontendConfig' import Session from 'supertokens-auth-react/recipe/session' -import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword' if (typeof window !== 'undefined') { SuperTokensReact.init(SuperTokensConfig.frontendConfig()) diff --git a/examples/with-supertokens/pages/index.js b/examples/with-supertokens/pages/index.js index 41202162c3b4637..eb58d975f91378b 100644 --- a/examples/with-supertokens/pages/index.js +++ b/examples/with-supertokens/pages/index.js @@ -1,13 +1,15 @@ import React from 'react' import Head from 'next/head' import styles from '../styles/Home.module.css' -import ThirdPartyEmailPassword, { - ThirdPartyEmailPasswordAuth, -} from 'supertokens-auth-react/recipe/thirdpartyemailpassword' +import ThirdPartyEmailPassword from 'supertokens-auth-react/recipe/thirdpartyemailpassword' import supertokensNode from 'supertokens-node' import { backendConfig } from '../config/backendConfig' import Session from 'supertokens-node/recipe/session' -import { useSessionContext } from 'supertokens-auth-react/recipe/session' +import { + SessionAuth, + useSessionContext, +} from 'supertokens-auth-react/recipe/session' +import { redirectToAuth } from 'supertokens-auth-react' export async function getServerSideProps(context) { // this runs on the backend, so we must call init on supertokens-node SDK @@ -18,7 +20,10 @@ export async function getServerSideProps(context) { } catch (err) { if (err.type === Session.Error.TRY_REFRESH_TOKEN) { return { props: { fromSupertokens: 'needs-refresh' } } - } else if (err.type === Session.Error.UNAUTHORISED) { + } else if ( + err.type === Session.Error.UNAUTHORISED || + err.type === Session.Error.INVALID_CLAIMS + ) { return { props: {} } } else { throw err @@ -32,9 +37,9 @@ export async function getServerSideProps(context) { export default function Home(props) { return ( - + - + ) } @@ -43,7 +48,7 @@ function ProtectedPage({ userId }) { async function logoutClicked() { await ThirdPartyEmailPassword.signOut() - ThirdPartyEmailPassword.redirectToAuth() + redirectToAuth() } async function fetchUserData() { From 6a2eac4553550b89a8d8e4e5b505a8e10d61f6fa Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Tue, 20 Sep 2022 13:55:00 +0530 Subject: [PATCH 68/74] updates dependencies versions --- examples/with-supertokens/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 2b86accf4cf4e5d..29132b56d3c18d6 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -9,12 +9,12 @@ "next": "latest", "react": "^18.2.0", "react-dom": "^18.2.0", - "supertokens-auth-react": "^0.24.7", - "supertokens-node": "^11.2.0" + "supertokens-auth-react": "^0.26.0", + "supertokens-node": "^12.0.0" }, "devDependencies": { "@types/react": "18.0.17", "@types/node": "18.7.13", "typescript": "^4.8.2" } -} +} \ No newline at end of file From afb80642ca640b951a0cab122667a8d7ad7bfb22 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Wed, 21 Sep 2022 16:43:49 +0530 Subject: [PATCH 69/74] fixes linting --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index 29132b56d3c18d6..d82cc60d7a0b1fd 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -17,4 +17,4 @@ "@types/node": "18.7.13", "typescript": "^4.8.2" } -} \ No newline at end of file +} From 49d8bec24e4564697e0d8a4f29a52cd56fcabb6e Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Wed, 26 Oct 2022 01:45:51 +0530 Subject: [PATCH 70/74] updates dependency version --- examples/with-supertokens/config/frontendConfig.ts | 4 +++- examples/with-supertokens/package.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/with-supertokens/config/frontendConfig.ts b/examples/with-supertokens/config/frontendConfig.ts index 95c6e274ac70ca8..7ffbe4ca36425d7 100644 --- a/examples/with-supertokens/config/frontendConfig.ts +++ b/examples/with-supertokens/config/frontendConfig.ts @@ -8,7 +8,9 @@ export let frontendConfig = () => { return { appInfo, recipeList: [ - EmailVerificationReact.init(), + EmailVerificationReact.init({ + mode: 'REQUIRED', + }), ThirdPartyEmailPasswordReact.init({ signInAndUpFeature: { providers: [ diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index d82cc60d7a0b1fd..c4debef4179680d 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -9,7 +9,7 @@ "next": "latest", "react": "^18.2.0", "react-dom": "^18.2.0", - "supertokens-auth-react": "^0.26.0", + "supertokens-auth-react": "^0.27.0", "supertokens-node": "^12.0.0" }, "devDependencies": { From cac05106ef1058b0b2006e7257af2799b778a675 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Tue, 8 Nov 2022 20:18:21 +0530 Subject: [PATCH 71/74] fixes issue with infinite redirect for unauthorised error --- examples/with-supertokens/pages/index.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/with-supertokens/pages/index.tsx b/examples/with-supertokens/pages/index.tsx index 1e7494dda97b97f..43950b22f434545 100644 --- a/examples/with-supertokens/pages/index.tsx +++ b/examples/with-supertokens/pages/index.tsx @@ -20,10 +20,11 @@ export async function getServerSideProps(context) { } catch (err) { if (err.type === Session.Error.TRY_REFRESH_TOKEN) { return { props: { fromSupertokens: 'needs-refresh' } } - } else if ( - err.type === Session.Error.UNAUTHORISED || - err.type === Session.Error.INVALID_CLAIMS - ) { + } else if (err.type === Session.Error.UNAUTHORISED) { + // this will force the frontend to try and refresh which will fail + // clearing all cookies and redirecting the user to the login screen. + return { props: { fromSupertokens: 'needs-refresh' } } + } else if (err.type === Session.Error.INVALID_CLAIMS) { return { props: {} } } else { throw err From da2b7c2132a8756b150f65df44eff38aa10dfbf9 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Tue, 22 Nov 2022 11:15:39 +0530 Subject: [PATCH 72/74] updates use of getSession in SSR --- examples/with-supertokens/pages/index.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/with-supertokens/pages/index.tsx b/examples/with-supertokens/pages/index.tsx index 43950b22f434545..81c3c34567ec245 100644 --- a/examples/with-supertokens/pages/index.tsx +++ b/examples/with-supertokens/pages/index.tsx @@ -16,7 +16,11 @@ export async function getServerSideProps(context) { supertokensNode.init(backendConfig()) let session try { - session = await Session.getSession(context.req, context.res) + session = await Session.getSession(context.req, context.res, { + overrideGlobalClaimValidators: async function () { + return [] + }, + }) } catch (err) { if (err.type === Session.Error.TRY_REFRESH_TOKEN) { return { props: { fromSupertokens: 'needs-refresh' } } @@ -24,11 +28,8 @@ export async function getServerSideProps(context) { // this will force the frontend to try and refresh which will fail // clearing all cookies and redirecting the user to the login screen. return { props: { fromSupertokens: 'needs-refresh' } } - } else if (err.type === Session.Error.INVALID_CLAIMS) { - return { props: {} } - } else { - throw err } + throw err } return { From 261b413e3ebe726a19b62b5ed46be5d926ef67f1 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Fri, 25 Nov 2022 17:49:01 +0530 Subject: [PATCH 73/74] fixes redirection loop --- examples/with-supertokens/pages/auth/[[...path]].tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/with-supertokens/pages/auth/[[...path]].tsx b/examples/with-supertokens/pages/auth/[[...path]].tsx index c68106272715abe..45a62ed3c2bdce7 100644 --- a/examples/with-supertokens/pages/auth/[[...path]].tsx +++ b/examples/with-supertokens/pages/auth/[[...path]].tsx @@ -3,17 +3,19 @@ import React, { useEffect } from 'react' import styles from '../../styles/Home.module.css' import dynamic from 'next/dynamic' import SuperTokens from 'supertokens-auth-react' -import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword' +import { redirectToAuth } from 'supertokens-auth-react' const SuperTokensComponentNoSSR = dynamic( - new Promise((res) => res(SuperTokens.getRoutingComponent)), + new Promise((res) => res(SuperTokens.getRoutingComponent)) as any, { ssr: false } ) export default function Auth(): JSX.Element { useEffect(() => { if (SuperTokens.canHandleRoute() === false) { - redirectToAuth() + redirectToAuth({ + redirectBack: false, + }) } }, []) From 7ded6a83ef9e844ecb4189236db350bee4aacbf2 Mon Sep 17 00:00:00 2001 From: Alisher Date: Thu, 15 Dec 2022 11:31:29 +0600 Subject: [PATCH 74/74] chore: update supertokens-auth-react version --- examples/with-supertokens/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-supertokens/package.json b/examples/with-supertokens/package.json index c4debef4179680d..08c3c2259b25f43 100644 --- a/examples/with-supertokens/package.json +++ b/examples/with-supertokens/package.json @@ -9,7 +9,7 @@ "next": "latest", "react": "^18.2.0", "react-dom": "^18.2.0", - "supertokens-auth-react": "^0.27.0", + "supertokens-auth-react": "^0.28.0", "supertokens-node": "^12.0.0" }, "devDependencies": {