updatd logout links and login flow for nextauth

This commit is contained in:
2022-04-19 12:25:13 +01:00
parent 511a5ed98d
commit 3b1a49e561
9 changed files with 81 additions and 45 deletions
+16 -25
View File
@@ -19,6 +19,7 @@ import ServiceBanner from "../components/servicebanner";
import { setAccountDetails } from "../store/accountDetails/action";
import { getGovGatewayConfig } from "../store/govgateway/action";
import { wrapper } from "../store/store";
import { getSession, useSession, signIn, signOut } from "next-auth/react";
const Home = (props) => {
const {
@@ -42,7 +43,7 @@ const Home = (props) => {
//console.log("hashed email str", loginEmailStr);
_.isEmpty(loggedInUserId) != false && !hasGGCode
? console.log("no ggcode")
? console.log("no session")
: _.has(loggedInUserId, "value")
? _.isEmpty(loggedInUserId.value)
? router.replace({
@@ -157,15 +158,17 @@ export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
let thisSession = await getSession(ctx);
var relayToken = await getToken();
relayToken = relayToken.access_token;
console.log("gg code:", query.code);
console.log("gg local", query.ui_locales);
console.log("auth sess:", thisSession);
const showLoginCheck = process.env.SHOWLOGIN || false;
const hasLoginCode = typeof query.code != "undefined";
const hasLoginCode = thisSession != null;
let providerConfig = await getProviderConfig();
let ggLocale =
typeof query.ui_locales != "undefined" && query.ui_locales;
@@ -189,27 +192,15 @@ export const getServerSideProps = wrapper.getServerSideProps(
let loginEmailStr = "";
if (hasLoginCode == true) {
ggToken = await getGGToken(
providerConfig.token_endpoint,
query.code,
process.env.GG_REDIRECT_URI
);
_.has(ggToken, "access_token")
? ((ggUserInfo = await getUserInfo(
providerConfig.userinfo_endpoint,
ggToken.access_token
)),
(loginEmailStr = hashString(ggUserInfo.data.email)),
(portalUserObj = await getPortalLogin(
ggUserInfo.data.email,
relayToken
)),
console.log("loggin user stuff: ", portalUserObj),
store.dispatch(setAccountDetails(portalUserObj)))
: console.log(
ggToken.status + " " + ggToken.data.error_description
);
(loginEmailStr = hashString(thisSession.user.email)),
(portalUserObj = await getPortalLogin(
thisSession.user.email,
relayToken
)),
console.log("loggin user stuff: ", portalUserObj),
store.dispatch(setAccountDetails(portalUserObj));
} else {
console.log("no session");
}
if (ggToken.status == 400) {
+5 -1
View File
@@ -39,7 +39,7 @@ import {
} from "../../store/watchedCases/action";
import { setCookie } from "nookies";
import { useSession, signIn, signOut } from "next-auth/react";
import { getSession, useSession, signIn, signOut } from "next-auth/react";
const Home = (props) => {
const {
@@ -157,6 +157,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
let loggedInUser = cookies.pinsUser;
let thisSession = await getSession(ctx);
console.log("nextAuth Session:", thisSession);
let providerConfig = await getProviderConfig();
store.dispatch(getGovGatewayConfig(providerConfig));