Skip to content
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

(fix) Next-Auth integration #4153

Merged
merged 26 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
348d602
fix next-auth integration
siddhsuresh May 30, 2023
15a4c17
Create small-monkeys-battle.md
siddhsuresh May 30, 2023
69de5f9
Update .changeset/small-monkeys-battle.md
siddhsuresh May 30, 2023
0e97ad4
add a postinstall script for good measure
siddhsuresh May 30, 2023
66e1a41
Merge branch 'siddhsuresh/fix-next-auth-adapter' of https://github.co…
siddhsuresh May 30, 2023
55ba26f
add a postinstall script for good measure
siddhsuresh May 30, 2023
fb88d69
fix lock file
siddhsuresh May 30, 2023
22d60a4
upgrade pnpm
siddhsuresh May 30, 2023
a7b4540
fix version
siddhsuresh May 30, 2023
baece9a
fix build error
siddhsuresh May 30, 2023
56eb772
Merge branch 'siddhsuresh/fix-next-auth-adapter' of https://github.co…
siddhsuresh May 30, 2023
5f52f87
Merge branch 'main' into siddhsuresh/fix-next-auth-adapter
siddhsuresh Jun 5, 2023
2da9e66
suggessions
siddhsuresh Jun 5, 2023
91e5451
Merge branch 'main' into siddhsuresh/fix-next-auth-adapter
siddhsuresh Jun 5, 2023
cc80d82
Merge branch 'main' into siddhsuresh/fix-next-auth-adapter
siddhsuresh Jun 5, 2023
4bc7c7a
fix pnpm lock
siddhsuresh Jun 5, 2023
e2655a9
Merge branch 'siddhsuresh/fix-next-auth-adapter' of https://github.co…
siddhsuresh Jun 5, 2023
f1f357a
fix pnpm lock
siddhsuresh Jun 8, 2023
6ec7159
Update main.yml
siddhsuresh Jun 8, 2023
1fcf06f
Update apps/toolkit-app/next.config.js
siddhsuresh Jun 8, 2023
8f8a9a7
merge
siddhsuresh Jun 12, 2023
3e23037
next-auth working again
siddhsuresh Jun 12, 2023
27b08bc
Update apps/toolkit-app/.env
siddhsuresh Jun 12, 2023
55dc9cd
Merge branch 'main' into siddhsuresh/fix-next-auth-adapter
siddhsuresh Jun 13, 2023
5da9242
Update packages/blitz-auth/src/server/auth-sessions.ts
siddhsuresh Jun 13, 2023
5872761
Update packages/blitz-auth/src/server/auth-sessions.ts
siddhsuresh Jun 14, 2023
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
6 changes: 6 additions & 0 deletions .changeset/small-monkeys-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@blitzjs/auth": patch
"blitz": patch
---

Fix Next-Auth integration: `Unable to use next-auth with provider: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]`
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
- uses: pnpm/action-setup@v2.2.4
with:
version: 7.33.0
- name: Setup node
Expand All @@ -38,7 +38,7 @@ jobs:
name: Build
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
- uses: pnpm/action-setup@v2.2.4
with:
version: 7.33.0
- name: Setup node
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
uses: actions/checkout@v3

- name: Setup PNPM
uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
uses: pnpm/action-setup@v2.2.4
with:
version: 7.33.0

Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
uses: actions/checkout@v3

- name: Setup PNPM
uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
uses: pnpm/action-setup@v2.2.4
with:
version: 7.33.0

Expand Down
4 changes: 2 additions & 2 deletions apps/toolkit-app/next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { withNextAuthAdapter } = require("@blitzjs/auth/next-auth")
const { withNextAuthAdapter } = require("@blitzjs/auth")
const { withBlitz } = require("@blitzjs/next")

/**
* @type {import('@blitzjs/next').BlitzConfig}
* @type {import('next').NextConfig}
**/
const config = {
reactStrictMode: true,
Expand Down
4 changes: 2 additions & 2 deletions apps/toolkit-app/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const UserInfo = () => {
} else {
return (
<>
<Link href={Routes.SignupPage()} className={styles.button}>
<Link href={"/signup"} className={styles.button}>
<strong>Sign Up</strong>
</Link>
<Link href={Routes.LoginPage()} className={styles.loginButton}>
<Link href={"/login"} className={styles.loginButton}>
<strong>Login</strong>
</Link>
<Link href="/api/auth/github/login" passHref legacyBehavior>
Expand Down
2 changes: 2 additions & 0 deletions packages/blitz-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
"cookie": "0.4.1",
"cookie-session": "2.0.0",
"debug": "4.3.3",
"find-up": "4.1.0",
"http": "0.0.1-security",
"jsonwebtoken": "9.0.0",
"nanoid": "3.2.0",
"oauth": "0.10.0",
"openid-client": "5.2.1",
"passport": "0.6.0",
"path": "0.12.7",
"resolve-from": "5.0.0",
"supports-color": "8.1.1",
"url": "0.11.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/blitz-auth/src/server/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./passport/adapter"
export * from "./next-auth/webpack"
1 change: 0 additions & 1 deletion packages/blitz-auth/src/server/adapters/next-auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./next-auth/adapter"
export * from "./next-auth/types"
export * from "./next-auth/webpack"
11 changes: 3 additions & 8 deletions packages/blitz-auth/src/server/adapters/next-auth/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import type {
} from "./types"
import {Provider} from "next-auth/providers"

export {withNextAuthAdapter} from "./webpack"
import {init} from "next-auth/core/init"
import getAuthorizationUrl from "next-auth/core/lib/oauth/authorization-url"
import oAuthCallback from "next-auth/core/lib/oauth/callback"

const INTERNAL_REDIRECT_URL_KEY = "_redirectUrl"

Expand Down Expand Up @@ -102,7 +104,6 @@ export function NextAuthAdapter<P extends Provider[]>(
if (providerId?.includes("?")) {
providerId = providerId.split("?")[0]
}
const {init} = await import("next-auth/core/init").then((m) => m)
const {options, cookies} = await init({
// @ts-ignore
url: new URL(
Expand Down Expand Up @@ -158,9 +159,6 @@ async function AuthHandler<P extends Provider[]>(
if (action === "login") {
middleware.push(async (req, res, next) => {
try {
const getAuthorizationUrl = await import("next-auth/core/lib/oauth/authorization-url").then(
(m) => m.default,
)
const _signin = await getAuthorizationUrl({options: options, query: req.query})
if (_signin.cookies) cookies.push(..._signin.cookies)
const session = res.blitzCtx.session as SessionContext
Expand Down Expand Up @@ -191,9 +189,6 @@ async function AuthHandler<P extends Provider[]>(
middleware.push(
// eslint-disable-next-line no-shadow
connectMiddleware(async (req, res, next) => {
const oAuthCallback = await import("next-auth/core/lib/oauth/callback").then(
(m) => m.default,
)
try {
const {profile, account, OAuthProfile} = await oAuthCallback({
query: internalRequest.query,
Expand Down
28 changes: 20 additions & 8 deletions packages/blitz-auth/src/server/adapters/next-auth/webpack.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
//@ts-nocheck
import fs from "fs-extra"
import path from "path"

export function withNextAuthAdapter(nextConfig) {
siddhsuresh marked this conversation as resolved.
Show resolved Hide resolved
const config = Object.assign({}, nextConfig)
config.webpack = (config) => {
//add a required resolve alias
config.resolve.alias["next-auth/core/lib/oauth/callback"] =
process.cwd() + "/node_modules/next-auth/core/lib/oauth/callback.js"
config.resolve.alias["next-auth/core/lib/oauth/authorization-url"] =
process.cwd() + "/node_modules/next-auth/core/lib/oauth/authorization-url.js"
config.resolve.alias["next-auth/core/init"] =
process.cwd() + "/node_modules/next-auth/core/init.js"
const nextAuthPath = path.dirname(require.resolve("next-auth"))
const webpack = (config) => {
config.resolve.alias = {
...config.resolve.alias,
"next-auth/core/lib/oauth/callback": path.join(nextAuthPath, "core/lib/oauth/callback.js"),
"next-auth/core/lib/oauth/authorization-url": path.join(
nextAuthPath,
"core/lib/oauth/authorization-url.js",
),
"next-auth/core/init": path.join(nextAuthPath, "core/init.js"),
}
return config
}
if (typeof nextConfig.webpack === "function") {
config.webpack = (config, options) => {
return nextConfig.webpack(webpack(config), options)
}
}
config.webpack = webpack
return config
}
5 changes: 4 additions & 1 deletion packages/blitz-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"peerDependencies": {
"blitz": "2.0.0-beta.28",
"next": "*",
"react": "*"
"react": "*",
"tslog": "*"
},
"devDependencies": {
"@blitzjs/config": "workspace:2.0.0-beta.28",
Expand All @@ -49,6 +50,7 @@
"@testing-library/react": "13.4.0",
"@testing-library/react-hooks": "8.0.1",
"@testing-library/user-event": "13.5.0",
"@types/debug": "4.1.7",
"@types/node": "18.11.9",
"@types/react": "18.0.25",
"@types/react-dom": "17.0.14",
Expand All @@ -62,6 +64,7 @@
"react-dom": "18.2.0",
"resolve-from": "5.0.0",
"ts-jest": "27.1.4",
"tslog": "4.8.2",
"typescript": "^4.8.4",
"unbuild": "0.7.6",
"watch": "1.0.2"
Expand Down
Loading
Loading