Add logout route
This commit is contained in:
parent
08ab0afdb0
commit
49c26f70f7
@ -20,6 +20,7 @@ import * as apps from "./apps"
|
|||||||
import * as domainProxy from "./domainProxy"
|
import * as domainProxy from "./domainProxy"
|
||||||
import * as health from "./health"
|
import * as health from "./health"
|
||||||
import * as login from "./login"
|
import * as login from "./login"
|
||||||
|
import * as logout from "./logout"
|
||||||
import * as pathProxy from "./pathProxy"
|
import * as pathProxy from "./pathProxy"
|
||||||
// static is a reserved keyword.
|
// static is a reserved keyword.
|
||||||
import * as _static from "./static"
|
import * as _static from "./static"
|
||||||
@ -136,10 +137,10 @@ export const register = async (
|
|||||||
|
|
||||||
if (args.auth === AuthType.Password) {
|
if (args.auth === AuthType.Password) {
|
||||||
app.use("/login", login.router)
|
app.use("/login", login.router)
|
||||||
|
app.use("/logout", logout.router)
|
||||||
} else {
|
} else {
|
||||||
app.all("/login", (req, res) => {
|
app.all("/login", (req, res) => redirect(req, res, "/", {}))
|
||||||
redirect(req, res, "/", {})
|
app.all("/logout", (req, res) => redirect(req, res, "/", {}))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use("/static", _static.router)
|
app.use("/static", _static.router)
|
||||||
|
17
src/node/routes/logout.ts
Normal file
17
src/node/routes/logout.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { Router } from "express"
|
||||||
|
import { getCookieDomain, redirect } from "../http"
|
||||||
|
import { Cookie } from "./login"
|
||||||
|
|
||||||
|
export const router = Router()
|
||||||
|
|
||||||
|
router.get("/", async (req, res) => {
|
||||||
|
// Must use the *identical* properties used to set the cookie.
|
||||||
|
res.clearCookie(Cookie.Key, {
|
||||||
|
domain: getCookieDomain(req.headers.host || "", req.args["proxy-domain"]),
|
||||||
|
path: req.body.base || "/",
|
||||||
|
sameSite: "lax",
|
||||||
|
})
|
||||||
|
|
||||||
|
const to = (typeof req.query.to === "string" && req.query.to) || "/"
|
||||||
|
return redirect(req, res, to, { to: undefined, base: undefined })
|
||||||
|
})
|
Reference in New Issue
Block a user