Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Oct 10, 2022
1 parent aff9ba6 commit 8af1b3f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 75 deletions.
1 change: 0 additions & 1 deletion examples/auth0/README.md
Expand Up @@ -16,7 +16,6 @@ Read more: [https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/](

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:


```bash
npx create-next-app --example auth0 auth0-app
```
Expand Down
28 changes: 14 additions & 14 deletions examples/auth0/pages/_app.tsx
@@ -1,14 +1,14 @@
import { UserProvider } from '@auth0/nextjs-auth0'

export default function App({ Component, pageProps }) {
// optionally pass the 'user' prop from pages that require server-side
// rendering to prepopulate the 'useUser' hook.

const { user } = pageProps

return (
<UserProvider user={user}>
<Component {...pageProps} />
</UserProvider>
)
}
import { UserProvider } from '@auth0/nextjs-auth0'

export default function App({ Component, pageProps }) {
// optionally pass the 'user' prop from pages that require server-side
// rendering to prepopulate the 'useUser' hook.

const { user } = pageProps

return (
<UserProvider user={user}>
<Component {...pageProps} />
</UserProvider>
)
}
74 changes: 37 additions & 37 deletions examples/auth0/pages/advanced/api-profile.tsx
@@ -1,37 +1,37 @@
import { useEffect, useState } from 'react'
import { useUser } from '@auth0/nextjs-auth0'
import Layout from '../../components/layout'

const ApiProfile = () => {
const { user, isLoading } = useUser()

const [data, setData] = useState(null)

useEffect(() => {
(async () => {
const res = await fetch('/api/protected-api')

const data = await res.json()

setData(data)
})()
}, [])

return (
<Layout user={user} loading={isLoading}>
<h1>Profile</h1>

<div>
<h3>Public page (client rendered)</h3>
<p>We are fetching data on the client-side :</p>
<p>By making request to '/api/protected-api' serverless function</p>
<p>so without a valid session cookie will fail</p>
<p>{JSON.stringify(data)}</p>
</div>
</Layout>
)
}

// Public route.(CSR) also accessing API from the client-side.
// data is not cached when redirecting between pages.
export default ApiProfile
import { useEffect, useState } from 'react'
import { useUser } from '@auth0/nextjs-auth0'
import Layout from '../../components/layout'

const ApiProfile = () => {
const { user, isLoading } = useUser()

const [data, setData] = useState(null)

useEffect(() => {
;(async () => {
const res = await fetch('/api/protected-api')

const data = await res.json()

setData(data)
})()
}, [])

return (
<Layout user={user} loading={isLoading}>
<h1>Profile</h1>

<div>
<h3>Public page (client rendered)</h3>
<p>We are fetching data on the client-side :</p>
<p>By making request to '/api/protected-api' serverless function</p>
<p>so without a valid session cookie will fail</p>
<p>{JSON.stringify(data)}</p>
</div>
</Layout>
)
}

// Public route.(CSR) also accessing API from the client-side.
// data is not cached when redirecting between pages.
export default ApiProfile
6 changes: 3 additions & 3 deletions examples/auth0/pages/api/auth/[...auth0].tsx
@@ -1,3 +1,3 @@
import { handleAuth } from '@auth0/nextjs-auth0'

export default handleAuth()
import { handleAuth } from '@auth0/nextjs-auth0'

export default handleAuth()
40 changes: 20 additions & 20 deletions examples/auth0/pages/api/protected-api.ts
@@ -1,20 +1,20 @@
import { withApiAuthRequired, getSession } from '@auth0/nextjs-auth0'

// Serverless function
// Protected API, requests to '/api/protected' without a valid session cookie will fail

async function handle(req, res) {
const { user } = getSession(req, res)

try {
res.status(200).json({
session: 'true',
id: user.sub,
nickname: user.nickname,
})
} catch (e) {
res.status(500).json({ error: 'Unable to fetch', description: e })
}
}

export default withApiAuthRequired(handle)
import { withApiAuthRequired, getSession } from '@auth0/nextjs-auth0'

// Serverless function
// Protected API, requests to '/api/protected' without a valid session cookie will fail

async function handle(req, res) {
const { user } = getSession(req, res)

try {
res.status(200).json({
session: 'true',
id: user.sub,
nickname: user.nickname,
})
} catch (e) {
res.status(500).json({ error: 'Unable to fetch', description: e })
}
}

export default withApiAuthRequired(handle)

0 comments on commit 8af1b3f

Please sign in to comment.