This commit is contained in:
Karol Wypchlo 2021-02-13 18:34:09 +01:00
parent 9f9db78a8f
commit f2e6b028cc
1 changed files with 13 additions and 13 deletions

View File

@ -1,19 +1,19 @@
import superagent from "superagent"; import superagent from "superagent";
export default async (req, res) => { export default async (req, res) => {
if (!req.cookies.ory_kratos_session) { if (req.cookies.ory_kratos_session) {
try {
const auth = await superagent
.post("http://oathkeeper:4455/login")
.set("cookie", `ory_kratos_session=${req.cookies.ory_kratos_session}`);
res.setHeader("Set-Cookie", auth.header["set-cookie"]);
} catch (error) {
res.redirect(302, "/auth/login"); // credentials were correct but accounts service failed
}
res.redirect(302, req.query.return_to ?? "/");
} else {
res.redirect(302, "/auth/login"); // redirect to login page if kratos session is missing res.redirect(302, "/auth/login"); // redirect to login page if kratos session is missing
} }
try {
const auth = await superagent
.get("http://oathkeeper:4455/login")
.set("cookie", `ory_kratos_session=${req.cookies.ory_kratos_session}`);
res.setHeader("Set-Cookie", auth.header["set-cookie"]);
} catch (error) {
res.redirect(302, "/auth/login"); // credentials were correct but accounts service failed
}
res.redirect(302, req.query.return_to ?? "/");
}; };