Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/with-supertokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
9 changes: 7 additions & 2 deletions examples/with-supertokens/pages/_app.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -27,7 +27,12 @@ function MyApp({ Component, pageProps }) {
if (pageProps.fromSupertokens === 'needs-refresh') {
return null
}
return <Component {...pageProps} />

return (
<SuperTokensWrapper>
<Component {...pageProps} />
</SuperTokensWrapper>
)
}

export default MyApp
22 changes: 12 additions & 10 deletions examples/with-supertokens/pages/auth/[[...path]].js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -18,15 +18,17 @@ export default function Auth() {
}, [])

return (
<div className={styles.container}>
<Head>
<title>SuperTokens 💫</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<SuperTokensWrapper>
<div className={styles.container}>
<Head>
<title>SuperTokens 💫</title>
<link rel="icon" href="/favicon.ico" />
</Head>

<main className={styles.main}>
<SuperTokensComponentNoSSR />
</main>
</div>
<main className={styles.main}>
<SuperTokensComponentNoSSR />
</main>
</div>
</SuperTokensWrapper>
)
}
197 changes: 95 additions & 102 deletions examples/with-supertokens/pages/index.js
Original file line number Diff line number Diff line change
@@ -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())
Expand All @@ -37,9 +31,30 @@ export async function getServerSideProps(context) {

export default function Home(props) {
return (
<ThirdPartyEmailPasswordAuthNoSSR>
<ProtectedPage userId={props.userId} />
</ThirdPartyEmailPasswordAuthNoSSR>
<div className={styles.container}>
<Head>
<title>SuperTokens 💫</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
<ThirdPartyEmailPasswordAuth requireAuth={true}>
<ProtectedPage userId={props.userId} />
</ThirdPartyEmailPasswordAuth>
</main>
<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<img src="/vercel.svg" alt="Vercel Logo" className={styles.logo} />
</a>
</footer>
</div>
)
}

Expand All @@ -58,117 +73,95 @@ function ProtectedPage({ userId }) {
}

return (
<div className={styles.container}>
<Head>
<title>SuperTokens 💫</title>
<link rel="icon" href="/favicon.ico" />
</Head>

<main className={styles.main}>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
<p className={styles.description}>
You are authenticated with SuperTokens! (UserID: {userId})
</p>
<>
<p className={styles.description}>
You are authenticated with SuperTokens! (UserID: {userId})
</p>

<div
style={{
display: 'flex',
height: '70px',
alignItems: 'center',
justifyContent: 'flex-end',
paddingLeft: '75px',
paddingRight: '75px',
}}
>
<div
onClick={logoutClicked}
style={{
display: 'flex',
height: '70px',
width: '116px',
height: '42px',
backgroundColor: '#000000',
borderRadius: '10px',
cursor: 'pointer',
alignItems: 'center',
justifyContent: 'flex-end',
paddingLeft: '75px',
paddingRight: '75px',
justifyContent: 'center',
color: '#ffffff',
fontWeight: 'bold',
}}
>
<div
onClick={logoutClicked}
style={{
display: 'flex',
width: '116px',
height: '42px',
backgroundColor: '#000000',
borderRadius: '10px',
cursor: 'pointer',
alignItems: 'center',
justifyContent: 'center',
color: '#ffffff',
fontWeight: 'bold',
}}
>
SIGN OUT
</div>
SIGN OUT
</div>
</div>
<div
style={{
display: 'flex',
height: '70px',
alignItems: 'center',
justifyContent: 'flex-end',
paddingLeft: '75px',
paddingRight: '75px',
}}
>
<div
onClick={fetchUserData}
style={{
display: 'flex',
height: '70px',
width: '150px',
height: '42px',
backgroundColor: 'rgb(247 54 54)',
borderRadius: '10px',
cursor: 'pointer',
alignItems: 'center',
justifyContent: 'flex-end',
paddingLeft: '75px',
paddingRight: '75px',
justifyContent: 'center',
color: '#ffffff',
fontWeight: 'bold',
}}
>
<div
onClick={fetchUserData}
style={{
display: 'flex',
width: '150px',
height: '42px',
backgroundColor: 'rgb(247 54 54)',
borderRadius: '10px',
cursor: 'pointer',
alignItems: 'center',
justifyContent: 'center',
color: '#ffffff',
fontWeight: 'bold',
}}
>
FETCH USER API
</div>
FETCH USER API
</div>
</div>

<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h3>Documentation &rarr;</h3>
<p>Find in-depth information about Next.js features and API.</p>
</a>
<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h3>Documentation &rarr;</h3>
<p>Find in-depth information about Next.js features and API.</p>
</a>

<a href="https://nextjs.org/learn" className={styles.card}>
<h3>Learn &rarr;</h3>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
<a href="https://nextjs.org/learn" className={styles.card}>
<h3>Learn &rarr;</h3>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>

<a
href="https://github.com/vercel/next.js/tree/canary/examples"
className={styles.card}
>
<h3>Examples &rarr;</h3>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>
<a
href="https://github.com/vercel/next.js/tree/canary/examples"
className={styles.card}
>
<h3>Examples &rarr;</h3>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>

<a
href="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
>
<h3>Deploy &rarr;</h3>
<p>
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
</main>
<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
href="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
>
Powered by{' '}
<img src="/vercel.svg" alt="Vercel Logo" className={styles.logo} />
<h3>Deploy &rarr;</h3>
<p>Instantly deploy your Next.js site to a public URL with Vercel.</p>
</a>
</footer>
</div>
</div>
</>
)
}