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
+2 -2
View File
@@ -195,7 +195,7 @@ const RegisterForm = (props) => {
)}
/>
<Field
{/* <Field
name="pinswg_custom_password"
id="pinswg_custom_password"
component={RenderTextfield}
@@ -226,7 +226,7 @@ const RegisterForm = (props) => {
errorMsg={t(
"account:register-new-account-confirm-password-label-errormsg"
)}
/>
/> */}
</fieldset>
<fieldset className="govuk-fieldset">
<legend className="govuk-fieldset__legend govuk-fieldset__legend--m">
+18
View File
@@ -741,6 +741,24 @@ const Breadcrumbs = (props) => {
) : (
""
)}
{router.pathname == "/auth/signin" ? (
<>
<li className="govuk-breadcrumbs__list-item">
Sign in
</li>
</>
) : (
""
)}
{router.pathname == "/auth/verify-request" ? (
<>
<li className="govuk-breadcrumbs__list-item">
Check your email
</li>
</>
) : (
""
)}
{/* {!_.isEmpty(slug) ? (
<>
<li className="govuk-breadcrumbs__list-item">
+8 -1
View File
@@ -7,6 +7,9 @@ import { useDispatch, useSelector, shallowEqual, connect } from "react-redux";
import { setLogout } from "../store/accountDetails/action";
import _ from "lodash";
import { parseCookies, setCookie, destroyCookie } from "nookies";
import { useSession, signIn, signOut } from "next-auth/react";
const Header = (props) => {
let { t, lang } = useTranslation();
@@ -33,6 +36,9 @@ const Header = (props) => {
"/myportal/error",
"/accessibility",
"/details-about-cookies",
"/auth/verify-request",
"/auth/signin",
"/auth/error",
];
const hasContactLink = [
"/dns/application-process",
@@ -214,7 +220,8 @@ const Header = (props) => {
<a
onClick={() => {
destroyCookie({}, "pinsUser"),
window.localStorage.clear();
window.localStorage.clear(),
signOut({ callbackUrl: "/logout" });
}}
className="govuk-header__link govuk-!-margin-right-3"
>
+24 -12
View File
@@ -120,7 +120,7 @@ let Login = (props) => {
GG_REDIRECT_URI,
} = props;
const { session, status } = useSession();
const { data: session } = useSession();
const router = useRouter();
const { locale } = router;
@@ -226,18 +226,30 @@ let Login = (props) => {
{t("home:login-card-title")}
</h3>{" "}
<div className="govuk-form-group govuk-!-margin-top-4">
{" "}
Not Signed in
<div className="govuk-body">
{session && "Signed in as " + session.user?.email}
</div>
<br />
<button
className="govuk-button"
type="button"
onClick={() => signIn()}
>
Magic Link Sign in
</button>
{!session && (
<button
className="govuk-button withChevron govuk-button-cta"
type="button"
onClick={() => signIn("email")}
>
Sign in with email address
</button>
)}
{session && (
<button
className="govuk-button"
type="button"
onClick={() => signOut()}
>
Magic Link Sign Out
</button>
)}
</div>
<form onSubmit={handleSubmit(onHandleSubmit)}>
{/* <form onSubmit={handleSubmit(onHandleSubmit)}>
{validLoginID == false && (
<div className="govuk-error-message govuk-form-group--error">
Incorrect username or password
@@ -387,7 +399,7 @@ let Login = (props) => {
{t("home:login-contact-email")}
</a>
</p>
</div>
</div> */}
</div>
{/* <LoadingOverlay
+2 -1
View File
@@ -12,7 +12,7 @@ import Dns from "./homepage/dns";
const MainHome = (props) => {
let { t } = useTranslation();
const { showLogin, GG_REDIRECT_URI, GG_CLIENT_ID } = props;
const { showLogin, GG_REDIRECT_URI, GG_CLIENT_ID, session } = props;
const router = useRouter();
const { locale } = router;
@@ -33,6 +33,7 @@ const MainHome = (props) => {
<Login
GG_CLIENT_ID={GG_CLIENT_ID}
GG_REDIRECT_URI={GG_REDIRECT_URI}
session={session}
/>
)}
{/* <Inspectorate /> */}
+4 -1
View File
@@ -19,6 +19,8 @@ import { useState } from "react";
import TimeOut from "../components/timeout";
import UploadFile from "./myportal/uploadFile";
import { useSession, signIn, signOut } from "next-auth/react";
const MyPortal = (props) => {
const { showFileUpload } = props;
let { t } = useTranslation();
@@ -57,7 +59,8 @@ const MyPortal = (props) => {
console.log("////////////", "\n", "logout", "\n", "//////////");
destroyCookie({}, "pinsUser"),
window.localStorage.clear(),
router.replace(props.ggLogout);
//router.replace(props.ggLogout);
signOut({ callbackUrl: "/logout" });
};
return (
+2 -2
View File
@@ -27,7 +27,7 @@ export default function YourAccount() {
</div>
</div>
<div className="card-body">
{/* <div className="card-body">
<h3 className="heading-small card-heading">
{t("myportal:changepassword-card-title")}
</h3>
@@ -43,7 +43,7 @@ export default function YourAccount() {
</a>
</Link>
</div>
</div>
</div> */}
</div>
</>
);
+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));