-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f33ac4
commit 141ec7b
Showing
84 changed files
with
8,531 additions
and
8,283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { handleAuth, handleLogin, handleCallback } from '@auth0/nextjs-auth0/edge'; | ||
|
||
const redirectUri = `${process.env.AUTH0_BASE_URL}/api/edge-auth/callback`; | ||
|
||
export const GET = handleAuth({ | ||
login: handleLogin({ | ||
authorizationParams: { redirect_uri: redirectUri } | ||
}), | ||
callback: handleCallback({ redirectUri }), | ||
onError(req: Request, error: Error) { | ||
console.error(error); | ||
} | ||
}); | ||
|
||
export const runtime = 'edge'; | ||
//https://github.com/vercel/next.js/issues/51642 | ||
export const fetchCache = 'force-no-store'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getSession, withApiAuthRequired } from '@auth0/nextjs-auth0/edge'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
const GET = withApiAuthRequired(async () => { | ||
const session = await getSession(); | ||
|
||
return NextResponse.json(session?.user); | ||
}); | ||
|
||
export { GET }; | ||
|
||
export const runtime = 'edge'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use client'; | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
import { withPageAuthRequired } from '@auth0/nextjs-auth0/client'; | ||
|
||
export default withPageAuthRequired(function ProfileApi() { | ||
const [user, setUser] = useState(); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const res = await fetch(`${window.location.origin}/api/edge-profile`); | ||
setUser(await res.json()); | ||
})(); | ||
}, []); | ||
|
||
return ( | ||
<main> | ||
<h1>Profile (fetched from API)</h1> | ||
<h3>User</h3> | ||
<pre data-testid="profile-api">{JSON.stringify(user, null, 2)}</pre> | ||
</main> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { getSession, withPageAuthRequired } from '@auth0/nextjs-auth0/edge'; | ||
|
||
export default withPageAuthRequired( | ||
async function Page() { | ||
const session = await getSession(); | ||
|
||
return ( | ||
<main> | ||
<h1>Profile</h1> | ||
<h2>Page:</h2> | ||
<h3>Access Token</h3> | ||
<pre>{JSON.stringify({ accessToken: session?.accessToken }, null, 2)}</pre> | ||
<h3>User</h3> | ||
<pre data-testid="profile">{JSON.stringify(session?.user, null, 2)}</pre> | ||
</main> | ||
); | ||
}, | ||
{ returnTo: '/edge-profile' } | ||
); | ||
|
||
export const runtime = 'edge'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,11 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { Session, LoginOptions } from '@auth0/nextjs-auth0'; | ||
import { pageRouterAuth } from '../../../lib/auth0'; | ||
import { pageRouterAuth } from '@/lib/auth0'; | ||
|
||
const redirectUri = `${process.env.AUTH0_BASE_URL}/api/page-router-auth/callback`; | ||
|
||
export default pageRouterAuth.handleAuth({ | ||
login: pageRouterAuth.handleLogin({ | ||
authorizationParams: { redirect_uri: `${process.env.AUTH0_BASE_URL}/api/page-router-auth/callback` }, | ||
getLoginState(req: NextApiRequest, options: LoginOptions) { | ||
return { | ||
returnTo: options.returnTo, | ||
foo: 'bar' | ||
}; | ||
} | ||
}), | ||
callback: pageRouterAuth.handleCallback({ | ||
redirectUri: `${process.env.AUTH0_BASE_URL}/api/page-router-auth/callback`, | ||
afterCallback(_req: NextApiRequest, _res: NextApiResponse, session: Session) { | ||
return { ...session, foo: 'bar' }; | ||
} | ||
}), | ||
me: pageRouterAuth.handleProfile({ | ||
refetch: true, | ||
afterRefetch(req: NextApiRequest, res: NextApiResponse, session: Session) { | ||
return { ...session, foo: 'bar' }; | ||
} | ||
authorizationParams: { redirect_uri: redirectUri } | ||
}), | ||
callback: pageRouterAuth.handleCallback({ redirectUri }), | ||
logout: pageRouterAuth.handleLogout({ returnTo: `${process.env.AUTH0_BASE_URL}/page-router` }) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** @type {import('jest').Config} */ | ||
module.exports = { | ||
rootDir: '.', | ||
moduleFileExtensions: ['ts', 'tsx', 'js'], | ||
preset: 'ts-jest/presets/js-with-ts', | ||
globalSetup: './tests/global-setup.ts', | ||
setupFilesAfterEnv: ['./tests/setup.ts'], | ||
transformIgnorePatterns: ['/node_modules/(?!oauth4webapi)'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const base = require('./jest-base.config'); | ||
|
||
/** @type {import('jest').Config} */ | ||
module.exports = { | ||
...base, | ||
displayName: 'edge', | ||
testEnvironment: '@edge-runtime/jest-environment', | ||
testMatch: [ | ||
'**/tests/handlers/login.test.ts', | ||
'**/tests/handlers/logout.test.ts', | ||
'**/tests/handlers/callback.test.ts', | ||
'**/tests/handlers/profile.test.ts', | ||
'**/tests/http/auth0-next-request.test.ts', | ||
'**/tests/http/auth0-next-response.test.ts', | ||
'**/tests/helpers/with-middleware-auth-required.test.ts', | ||
'**/tests/session/get-access-token.test.ts' | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const base = require('./jest-base.config'); | ||
|
||
/** @type {import('jest').Config} */ | ||
module.exports = { | ||
...base, | ||
displayName: 'node', | ||
testEnvironment: 'jest-environment-node-single-context' | ||
}; |
Oops, something went wrong.