Skip to content

Commit

Permalink
Switch logout to Route Handler instead of middleware + Server Compone…
Browse files Browse the repository at this point in the history
…nt (#4)

Co-authored-by: Karl Horky <karl.horky@gmail.com>
  • Loading branch information
Josehower and karlhorky authored Mar 4, 2023
1 parent 44845e4 commit 396be3e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-playwright-and-deploy-to-fly-io.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: grep package.json -e '@ts-safeql/eslint-plugin' || yarn add @ts-safeql/eslint-plugin libpg-query
- run: yarn migrate up
# Also generates next-env.d.ts, required for tsc
- name: Build localhost
- name: Build Next.js app
run: yarn build
- name: Run TypeScript Compiler
run: yarn tsc
Expand Down
18 changes: 0 additions & 18 deletions app/(auth)/logout/page.tsx

This file was deleted.

24 changes: 24 additions & 0 deletions app/(auth)/logout/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import cookie from 'cookie';
import { cookies } from 'next/headers';
import { NextResponse } from 'next/server';
import { deleteSessionByToken } from '../../../database/sessions';

export async function GET() {
const cookieStore = cookies();
const token = cookieStore.get('sessionToken');

if (token) {
await deleteSessionByToken(token.value);
}

return new NextResponse(null, {
status: 307,
headers: {
'Set-Cookie': cookie.serialize('sessionToken', '', {
maxAge: -1,
expires: new Date(Date.now() - 10000),
}),
location: '/',
},
});
}
33 changes: 0 additions & 33 deletions middleware.ts

This file was deleted.

44 changes: 44 additions & 0 deletions patches/next+13.2.3.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
diff --git a/node_modules/next/dist/build/webpack/plugins/next-types-plugin.js b/node_modules/next/dist/build/webpack/plugins/next-types-plugin.js
index 8532ab0..357f3f1 100644
--- a/node_modules/next/dist/build/webpack/plugins/next-types-plugin.js
+++ b/node_modules/next/dist/build/webpack/plugins/next-types-plugin.js
@@ -273,7 +273,7 @@ class NextTypesPlugin {
if (!this.typedRoutes) return;
const isApp = filePath.startsWith(this.appDir + _path.default.sep);
// Filter out non-page files in app dir
- if (isApp && !/[/\\]page\.[^.]+$/.test(filePath)) {
+ if (isApp && !/[/\\](?:page|route)\.[^.]+$/.test(filePath)) {
return;
}
// Filter out non-page files in pages dir
@@ -306,7 +306,7 @@ class NextTypesPlugin {
const relativePathToApp = _path.default.relative(this.appDir, mod.resource);
const relativePathToRoot = _path.default.relative(this.dir, mod.resource);
if (!this.dev) {
- if (IS_PAGE) {
+ if (IS_PAGE || /[/\\]route\.[^.]+$/.test(mod.resource)) {
this.collectPage(mod.resource);
}
}
@@ -341,7 +341,7 @@ class NextTypesPlugin {
chunkGroup.chunks.forEach((chunk)=>{
if (!chunk.name) return;
// Here we only track page chunks.
- if (!chunk.name.startsWith("pages/") && !(chunk.name.startsWith("app/") && chunk.name.endsWith("/page"))) {
+ if (!chunk.name.startsWith("pages/") && !(chunk.name.startsWith("app/") && (chunk.name.endsWith("/page") || chunk.name.endsWith('/route')))) {
return;
}
const chunkModules = compilation.chunkGraph.getChunkModulesIterable(chunk);
diff --git a/node_modules/next/dist/client/components/layout-router.js b/node_modules/next/dist/client/components/layout-router.js
index 9b60a45..dd0639d 100644
--- a/node_modules/next/dist/client/components/layout-router.js
Expand All @@ -22,3 +53,16 @@ index d15ce7f..369e036 100644
} else {
navigate();
}
diff --git a/node_modules/next/dist/server/initialize-require-hook.js b/node_modules/next/dist/server/initialize-require-hook.js
index 774f9e1..e644086 100644
--- a/node_modules/next/dist/server/initialize-require-hook.js
+++ b/node_modules/next/dist/server/initialize-require-hook.js
@@ -1,7 +1,7 @@
"use strict";
var _requireHook = require("../build/webpack/require-hook");
(0, _requireHook).loadRequireHook();
-const isPrebundled = false;
+const isPrebundled = true;
if (isPrebundled) {
(0, _requireHook).overrideBuiltInReactPackages();
}

0 comments on commit 396be3e

Please sign in to comment.