Skip to content

Commit 6d4c81f

Browse files
committed
Add logout route
1 parent 4b76251 commit 6d4c81f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/node/routes/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as apps from "./apps"
2020
import * as domainProxy from "./domainProxy"
2121
import * as health from "./health"
2222
import * as login from "./login"
23+
import * as logout from "./logout"
2324
import * as pathProxy from "./pathProxy"
2425
// static is a reserved keyword.
2526
import * as _static from "./static"
@@ -136,10 +137,10 @@ export const register = async (
136137

137138
if (args.auth === AuthType.Password) {
138139
app.use("/login", login.router)
140+
app.use("/logout", logout.router)
139141
} else {
140-
app.all("/login", (req, res) => {
141-
redirect(req, res, "/", {})
142-
})
142+
app.all("/login", (req, res) => redirect(req, res, "/", {}))
143+
app.all("/logout", (req, res) => redirect(req, res, "/", {}))
143144
}
144145

145146
app.use("/static", _static.router)

src/node/routes/logout.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Router } from "express"
2+
import { getCookieDomain, redirect } from "../http"
3+
import { Cookie } from "./login"
4+
5+
export const router = Router()
6+
7+
router.get("/", async (req, res) => {
8+
// Must use the *identical* properties used to set the cookie.
9+
res.clearCookie(Cookie.Key, {
10+
domain: getCookieDomain(req.headers.host || "", req.args["proxy-domain"]),
11+
path: req.body.base || "/",
12+
sameSite: "lax",
13+
})
14+
15+
const to = (typeof req.query.to === "string" && req.query.to) || "/"
16+
return redirect(req, res, to, { to: undefined, base: undefined })
17+
})

0 commit comments

Comments
 (0)