From f2e6b028cc57dd81dc150a2a81bcbe357ebbbe10 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Sat, 13 Feb 2021 18:34:09 +0100 Subject: [PATCH] use post --- .../src/pages/api/accounts/authenticate.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/dashboard/src/pages/api/accounts/authenticate.js b/packages/dashboard/src/pages/api/accounts/authenticate.js index b48b75b3..8549625f 100644 --- a/packages/dashboard/src/pages/api/accounts/authenticate.js +++ b/packages/dashboard/src/pages/api/accounts/authenticate.js @@ -1,19 +1,19 @@ import superagent from "superagent"; 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 } - - 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 ?? "/"); };