From 427895bb151cd82fa50c03d202c1ec05cf6e78a4 Mon Sep 17 00:00:00 2001 From: TechQuery Date: Fri, 23 Aug 2024 06:30:57 +0800 Subject: [PATCH] [fix] Host Domain of OAuth 2 signer --- package.json | 4 ++-- source/middleware/remote.ts | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6a73704..113b223 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-ssr-middleware", - "version": "0.8.5", + "version": "0.8.6", "license": "LGPL-3.0-or-later", "author": "shiy2008@gmail.com", "description": "Koa-like middlewares for Next.js Server Side Rendering", @@ -36,7 +36,7 @@ "husky": "^9.1.5", "koajax": "^2.0.0", "lint-staged": "^15.2.9", - "next": "^14.2.5", + "next": "^14.2.6", "open-cli": "^8.0.0", "prettier": "^3.3.3", "typedoc": "^0.26.6", diff --git a/source/middleware/remote.ts b/source/middleware/remote.ts index 74f31e8..acf0abc 100644 --- a/source/middleware/remote.ts +++ b/source/middleware/remote.ts @@ -20,8 +20,8 @@ export interface OAuth2Props { user: T; } -const { VERCEL_URL } = process.env; -const Host = VERCEL_URL ? `https://${VERCEL_URL}` : 'http://127.0.0.1:3000'; +const DOMAIN = process.env.VERCEL_PROJECT_PRODUCTION_URL; +const Host = DOMAIN ? `https://${DOMAIN}` : 'http://127.0.0.1:3000'; export function oauth2Signer({ signInURL, @@ -31,7 +31,9 @@ export function oauth2Signer({ }: OAuth2Option): Middleware { return async ({ req: { url, headers, cookies }, query, res }, next) => { const token = cookies[tokenKey]; - const pageURL = new URL(url || '/', headers['origin'] || Host) + ''; + const pageURL = + new URL(url || '/', headers['origin'] || headers['host'] || Host) + + ''; if (query.code) { const token = await accessToken(query as OAuth2Ticket);