@sqrzro/server 2.0.0-bz.23 → 2.0.0-bz.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,10 @@ function redirect(request, pathname = DEFAULT_REDIRECT) {
14
14
  }
15
15
  return applyHeaders(request, NextResponse.redirect(`${request.nextUrl.origin}${pathname}?r=${encodeURIComponent(getRelativeUrl(request.nextUrl))}`));
16
16
  }
17
+ /*
18
+ * When deployed to Vercel in a preview environment, we need to bypass the protection when fetching
19
+ * the session from the API.
20
+ */
17
21
  function bypassProtection() {
18
22
  const headers = new Headers();
19
23
  if (process.env.VERCEL_PROTECTION_BYPASS) {
@@ -22,26 +26,20 @@ function bypassProtection() {
22
26
  return { headers };
23
27
  }
24
28
  export async function handleMiddleware(request, nextFn) {
25
- console.log('middleware', request.nextUrl.pathname);
26
29
  // If the URL is /api/session, we should just return the response, otherwise we end up in a loop
27
30
  if (request.nextUrl.pathname === '/api/session') {
28
- console.log('URL is /api/session, returning');
29
31
  return applyHeaders(request, nextFn ? nextFn() : NextResponse.next());
30
32
  }
31
- console.log('URL is not /api/session, continuing');
32
33
  const sessionID = request.cookies.get(process.env.AUTH_COOKIE_NAME || 'auth_session')?.value || '';
33
- console.log(sessionID);
34
34
  try {
35
35
  const session = await fetch(`${request.nextUrl.origin}/api/session?id=${sessionID}&pathname=${request.nextUrl.pathname}`, bypassProtection());
36
36
  const json = (await session.json());
37
- console.log('json', json);
38
37
  if (json.redirect === null) {
39
38
  return applyHeaders(request, nextFn ? nextFn() : NextResponse.next());
40
39
  }
41
40
  return redirect(request, json.redirect);
42
41
  }
43
42
  catch (err) {
44
- console.log('error', err);
45
43
  return redirect(request);
46
44
  }
47
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sqrzro/server",
3
- "version": "2.0.0-bz.23",
3
+ "version": "2.0.0-bz.24",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "ISC",