-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SDK-4319] Add support for Edge runtime #1269
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
legacyBehavior
still needed here (and in other links)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just moving this over from the old example app, I could change them - but I'd rather do that in another PR