Skip to content

Commit 5c7a883

Browse files
Merge pull request #7 from metabase/logout
Implement single logout
2 parents ef59230 + 2002715 commit 5c7a883

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

index.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const hash = require("pbkdf2-password")();
1717
const path = require("path");
1818
const session = require("express-session");
1919
const jwt = require("jsonwebtoken");
20-
const url = require("url");
2120

2221
var app = (module.exports = express());
2322

@@ -140,11 +139,16 @@ app.get("/analytics", restrict, function (req, res) {
140139
});
141140

142141
app.get("/logout", function (req, res) {
143-
// destroy the user's session to log them out
144-
// will be re-created next request
145-
req.session.destroy(function () {
146-
res.redirect("/");
147-
});
142+
const mbLogoutUrl = new URL("/auth/logout", METABASE_SITE_URL);
143+
144+
// destroy the user's session to log them out
145+
// will be re-created next request
146+
req.session.destroy(function () {
147+
// sign user out of Metabase by loading /auth/logout in a hidden iframe
148+
res.send(`
149+
You have been logged out. <a href="/login">Log in</a>
150+
<iframe src="${mbLogoutUrl}" hidden></iframe>`);
151+
});
148152
});
149153

150154
app.get("/login", function (req, res) {
@@ -184,15 +188,11 @@ app.post("/login", function (req, res, next) {
184188
});
185189

186190
app.get("/sso/metabase", restrict, (req, res) => {
187-
res.redirect(
188-
url.format({
189-
pathname: `${METABASE_SITE_URL}/auth/sso`,
190-
query: {
191-
jwt: signUserToken(req.session.user),
192-
return_to: `${req.query.return_to || "/"}?${mods}`,
193-
},
194-
})
195-
);
191+
const ssoUrl = new URL("/auth/sso", METABASE_SITE_URL);
192+
ssoUrl.searchParams.set("jwt", signUserToken(req.session.user));
193+
ssoUrl.searchParams.set("return_to", `${req.query.return_to ?? "/"}?${mods}`);
194+
195+
res.redirect(ssoUrl);
196196
});
197197

198198
const PORT = 8080;

0 commit comments

Comments
 (0)