diff --git a/.env b/.env index 4761d5a7..3f295570 100644 --- a/.env +++ b/.env @@ -33,11 +33,11 @@ AUTH_URL # Github OAuth APP 配置 # 下面这对配置可以用于 http://localhost:PORT,其它地址用不了!请务必及时替换为你自己的! -AUTH_GITHUB_ID = 62519d5cf7e8098627cf -AUTH_GITHUB_SECRET = cd46f95c2186109c65c6b0bb874a8da6a02868a3 +AUTH_GITHUB_ID = Ov23lit5CvhIVzhNgubm +AUTH_GITHUB_SECRET = f8ab00b9a09bba69c65752ba32d8987b1b9b8d4d -# 加密令牌用到的密钥。建议使用 UUID。 -AUTH_SECRET = "请把我替换为一个UUID" +# ! 用于加密令牌用到的密钥。请及时替换 UUID。 +AUTH_SECRET = "f8ab00b9a09bba69c65752ba32d8987b1b9b8d4d" # ================================================================================ diff --git a/next.config.js b/next.config.js index e36036d4..9936dc2e 100644 --- a/next.config.js +++ b/next.config.js @@ -18,8 +18,15 @@ export default async function setup() { dangerouslyAllowSVG: true, }, - webpack: (config) => { + webpack: (config, { webpack, nextRuntime }) => { config.plugins.push(codeInspectorPlugin({ bundler: 'webpack', hideDomPathAttr: false })) + // https://github.com/vercel/next.js/discussions/39705 + // fix: edge 环境无法加载环境变量 + if (nextRuntime === 'edge') { + config.plugins.push(new webpack.DefinePlugin({ + "process.env.AUTH_SECRET": JSON.stringify(process.env.AUTH_SECRET), + })) + } return config }, } diff --git a/src/middleware.ts b/src/middleware.ts index 51dbab6a..e48dae04 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -15,12 +15,15 @@ export default auth((req) => { } // 默认为 true,仅对于少数请求免除验证 let checkAdmin = true - const prefixes = ['/_next', '/api/auth', '/tag'] - const affixes = ['.svg', '.png'] + const whitelist = { + prefixes: ['/_next', '__next', '/api/auth', '/tag'], + affixes: ['.svg', '.png'], + pathnames: ['/', '/recent', '/search', '/login', '/forbidden', '/404', '/500', '/_error'], + } if ( - affixes.some((p) => pathname.endsWith(p)) || - prefixes.some((p) => pathname.startsWith(p)) || - ['/', '/recent', '/search', '/login', '/forbidden'].includes(pathname) + whitelist.affixes.some((p) => pathname.endsWith(p)) || + whitelist.prefixes.some((p) => pathname.startsWith(p)) || + whitelist.pathnames.includes(pathname) ) { checkAdmin = false } @@ -35,3 +38,10 @@ export default auth((req) => { } return NextResponse.next() }) + +console.log( + 'envs:', + process.env.AUTH_SECRET, + process.env.MY_SECRET, + process.env.FETCH_GITHUB_TOKEN_PROXY +)