Unverified Commit f00f4bd9 authored by NkxxkN's avatar NkxxkN Committed by GitHub

Examples bump supertokens (#22764)

Hey team!
We are updating the `with-supertokens` example to reflect the use of credentials alongside third party login

See: 
![image](https://user-images.githubusercontent.com/5072452/109943811-dd714b80-7cd5-11eb-91b5-5a966a1c1e2d.png)

This PR bumps the versions and add a base example implementation.
parent 2046648f
...@@ -3,3 +3,15 @@ NEXT_PUBLIC_APP_URL="http://localhost:3000" ...@@ -3,3 +3,15 @@ NEXT_PUBLIC_APP_URL="http://localhost:3000"
# Secret environment variables only available to Node.js # Secret environment variables only available to Node.js
APP_URL="http://localhost:3000" 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=
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
"next": "latest", "next": "latest",
"react": "17.0.1", "react": "17.0.1",
"react-dom": "17.0.1", "react-dom": "17.0.1",
"supertokens-auth-react": "^0.6.0", "supertokens-auth-react": "^0.7.0",
"supertokens-node": "^4.0.0" "supertokens-node": "^4.1.0"
}, },
"license": "MIT" "license": "MIT"
} }
import '../styles/globals.css' import '../styles/globals.css'
import React from 'react' import React from 'react'
import SuperTokensReact from 'supertokens-auth-react' import SuperTokensReact from 'supertokens-auth-react'
import EmailPasswordReact from 'supertokens-auth-react/recipe/emailpassword' import ThirdPartyEmailPasswordReact from 'supertokens-auth-react/recipe/thirdpartyemailpassword'
import SessionReact from 'supertokens-auth-react/recipe/session' import SessionReact from 'supertokens-auth-react/recipe/session'
import SuperTokensNode from 'supertokens-node' import SuperTokensNode from 'supertokens-node'
import SessionNode from 'supertokens-node/recipe/session' import SessionNode from 'supertokens-node/recipe/session'
import EmailPasswordNode from 'supertokens-node/recipe/emailpassword' import ThirdPartyEmailPasswordNode from 'supertokens-node/recipe/thirdpartyemailpassword'
const port = process.env.APP_PORT || 3000 const port = process.env.APP_PORT || 3000
const websiteDomain = const websiteDomain =
process.env.APP_URL || process.env.APP_URL ||
...@@ -24,10 +24,17 @@ if (typeof window !== 'undefined') { ...@@ -24,10 +24,17 @@ if (typeof window !== 'undefined') {
apiBasePath, apiBasePath,
}, },
recipeList: [ recipeList: [
EmailPasswordReact.init({ ThirdPartyEmailPasswordReact.init({
emailVerificationFeature: { emailVerificationFeature: {
mode: 'REQUIRED', mode: 'REQUIRED',
}, },
signInAndUpFeature: {
providers: [
ThirdPartyEmailPasswordReact.Google.init(),
ThirdPartyEmailPasswordReact.Github.init(),
ThirdPartyEmailPasswordReact.Facebook.init(),
],
},
}), }),
SessionReact.init(), SessionReact.init(),
], ],
...@@ -44,7 +51,25 @@ if (typeof window !== 'undefined') { ...@@ -44,7 +51,25 @@ if (typeof window !== 'undefined') {
apiDomain: websiteDomain, apiDomain: websiteDomain,
apiBasePath, apiBasePath,
}, },
recipeList: [EmailPasswordNode.init(), SessionNode.init()], recipeList: [
ThirdPartyEmailPasswordNode.init({
providers: [
ThirdPartyEmailPasswordNode.Google({
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
clientId: process.env.GOOGLE_CLIENT_ID,
}),
ThirdPartyEmailPasswordNode.Github({
clientSecret: process.env.GITHUB_CLIENT_SECRET,
clientId: process.env.GITHUB_CLIENT_ID,
}),
ThirdPartyEmailPasswordNode.Facebook({
clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
clientId: process.env.FACEBOOK_CLIENT_ID,
}),
],
}),
SessionNode.init(),
],
}) })
} }
......
import React from 'react' import React from 'react'
import Head from 'next/head' import Head from 'next/head'
import styles from '../styles/Home.module.css' import styles from '../styles/Home.module.css'
import EmailPassword from 'supertokens-auth-react/recipe/emailpassword' import ThirdPartyEmailPassword from 'supertokens-auth-react/recipe/thirdpartyemailpassword'
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
const EmailPasswordAuthNoSSR = dynamic( const ThirdPartyEmailPasswordAuthNoSSR = dynamic(
() => Promise.resolve().then(() => EmailPassword.EmailPasswordAuth), () =>
Promise.resolve().then(
() => ThirdPartyEmailPassword.ThirdPartyEmailPasswordAuth
),
{ {
ssr: false, ssr: false,
} }
...@@ -13,7 +16,7 @@ const EmailPasswordAuthNoSSR = dynamic( ...@@ -13,7 +16,7 @@ const EmailPasswordAuthNoSSR = dynamic(
export default function Home() { export default function Home() {
async function logoutClicked() { async function logoutClicked() {
await EmailPassword.signOut() await ThirdPartyEmailPassword.signOut()
window.location.href = '/auth' window.location.href = '/auth'
} }
...@@ -34,7 +37,7 @@ export default function Home() { ...@@ -34,7 +37,7 @@ export default function Home() {
<h1 className={styles.title}> <h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a> Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1> </h1>
<EmailPasswordAuthNoSSR> <ThirdPartyEmailPasswordAuthNoSSR>
<p className={styles.description}> <p className={styles.description}>
You are authenticated with SuperTokens! You are authenticated with SuperTokens!
</p> </p>
...@@ -95,7 +98,7 @@ export default function Home() { ...@@ -95,7 +98,7 @@ export default function Home() {
FETCH USER API FETCH USER API
</div> </div>
</div> </div>
</EmailPasswordAuthNoSSR> </ThirdPartyEmailPasswordAuthNoSSR>
<div className={styles.grid}> <div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}> <a href="https://nextjs.org/docs" className={styles.card}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment