-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converted login modal to FC. Added formik lib. #638
base: master
Are you sure you want to change the base?
Conversation
@@ -19,232 +19,174 @@ | |||
* | |||
*/ | |||
|
|||
import React, { Component } from 'react'; | |||
import React, { Component, useState, useEffect } from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import Component
now that this is a functional component
import { Link } from 'react-router-dom'; | ||
import Modal from 'react-responsive-modal'; | ||
import { FormikErrors, useFormik } from 'formik'; | ||
import queryString from 'query-string'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unused import
import { Link } from 'react-router-dom'; | ||
import Modal from 'react-responsive-modal'; | ||
import { FormikErrors, useFormik } from 'formik'; | ||
import queryString from 'query-string'; | ||
import { loginRegistered, loginRegisteredAuthService } from '../utils/AuthService'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unused import loginRegisteredAuthService
|
||
const [failedLogin, setFailedLogin] = useState(false); | ||
|
||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we resetting the configuration every time on each render?
@@ -47,19 +47,21 @@ export class LoginRedirectPage extends React.Component<LoginRedirectPageProps, L | |||
const locationData = window.location.search; | |||
const url = locationData; | |||
const params = queryString.parse(url); | |||
if (Config.b2b.openId && Config.b2b.openId.enable && params.code && params.session_state) { | |||
const b2bEnabled = Config.b2b.openId && Config.b2b.openId.enable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is checking if openID is enabled, not if b2b is enabled. We have a separate config for that
const b2bEnabled = Config.b2b.openId && Config.b2b.openId.enable; | |
const openidEnabled = Config.b2b.openId && Config.b2b.openId.enable; |
if (Config.b2b.openId && Config.b2b.openId.enable && params.code && params.session_state) { | ||
const b2bEnabled = Config.b2b.openId && Config.b2b.openId.enable; | ||
|
||
if (b2bEnabled && params.code && params.session_state) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (b2bEnabled && params.code && params.session_state) { | |
if (openidEnabled && params.code && params.session_state) { |
localStorage.setItem(`${Config.cortexApi.scope}_openIdcCode`, params.code); | ||
localStorage.setItem(`${Config.cortexApi.scope}_openIdcSessionState`, params.session_state); | ||
localStorage.removeItem('OidcSecret'); | ||
} | ||
|
||
const oidcParameters: OidcParameters = await LoginRedirectPage.discoverOIDCParameters(); | ||
const redirectUri = encodeURIComponent(((Config.b2b.openId && Config.b2b.openId.enable) ? `${window.location.origin}/loggedin` : Config.b2b.keycloak.callbackUrl)); | ||
const clientId = encodeURIComponent(((Config.b2b.openId && Config.b2b.openId.enable) ? oidcParameters.clientId : Config.b2b.keycloak.client_id)); | ||
const redirectUri = encodeURIComponent((b2bEnabled ? `${window.location.origin}/loggedin` : Config.b2b.keycloak.callbackUrl)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const redirectUri = encodeURIComponent((b2bEnabled ? `${window.location.origin}/loggedin` : Config.b2b.keycloak.callbackUrl)); | |
const redirectUri = encodeURIComponent((openidEnabled ? `${window.location.origin}/loggedin` : Config.b2b.keycloak.callbackUrl)); |
const redirectUri = encodeURIComponent(((Config.b2b.openId && Config.b2b.openId.enable) ? `${window.location.origin}/loggedin` : Config.b2b.keycloak.callbackUrl)); | ||
const clientId = encodeURIComponent(((Config.b2b.openId && Config.b2b.openId.enable) ? oidcParameters.clientId : Config.b2b.keycloak.client_id)); | ||
const redirectUri = encodeURIComponent((b2bEnabled ? `${window.location.origin}/loggedin` : Config.b2b.keycloak.callbackUrl)); | ||
const clientId = encodeURIComponent((b2bEnabled ? oidcParameters.clientId : Config.b2b.keycloak.client_id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const clientId = encodeURIComponent((b2bEnabled ? oidcParameters.clientId : Config.b2b.keycloak.client_id)); | |
const clientId = encodeURIComponent((openidEnabled ? oidcParameters.clientId : Config.b2b.keycloak.client_id)); |
|
||
const [failedLogin, setFailedLogin] = useState(false); | ||
|
||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to grab this config again on every render?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nvm, the empty array implies a render count of only 1, and not "starting at 1". This looks great 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah true. But why is it wrapped in the useEffect() method if we only want to set it once? Couldn't we just place it as a constant at the top of the function?
Tested locally and added a few comments. No further comments to this one. Thanks for this one @dusanradovanovic !! |
Description:
Converted AppModalLoginMain to be a functional component and removed problematic
componentWillMount
lifecycle method. Also addedformik
library for handling login form.Linting:
Component Updates:
Tests:
e2e
)Documentation: