-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat(ui): added logout functionality to epic #17045
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
// Libraries | ||
import {PureComponent} from 'react' | ||
import {FC, useEffect} from 'react' | ||
import {withRouter, WithRouterProps} from 'react-router' | ||
import auth0js from 'auth0-js' | ||
|
||
// APIs | ||
import {postSignout} from 'src/client' | ||
import {getAuth0Config} from 'src/authorizations/apis' | ||
|
||
// Constants | ||
import {CLOUD, CLOUD_URL, CLOUD_LOGOUT_PATH} from 'src/shared/constants' | ||
|
||
// Components | ||
import {ErrorHandling} from 'src/shared/decorators/errors' | ||
|
||
type Props = WithRouterProps | ||
|
||
@ErrorHandling | ||
export class Logout extends PureComponent<Props> { | ||
public componentDidMount() { | ||
this.handleSignOut() | ||
} | ||
|
||
public render() { | ||
return null | ||
} | ||
|
||
private handleSignOut = async () => { | ||
// Utils | ||
import {isFlagEnabled} from 'src/shared/utils/featureFlag' | ||
|
||
const Logout: FC<WithRouterProps> = ({router}) => { | ||
const handleSignOut = async () => { | ||
if (CLOUD && isFlagEnabled('regionBasedLoginPage')) { | ||
const config = await getAuth0Config() | ||
const auth0 = new auth0js.WebAuth({ | ||
domain: config.domain, | ||
clientID: config.clientID, | ||
}) | ||
auth0.logout({}) | ||
return | ||
} | ||
if (CLOUD) { | ||
window.location.href = `${CLOUD_URL}${CLOUD_LOGOUT_PATH}` | ||
return | ||
|
@@ -34,9 +37,14 @@ export class Logout extends PureComponent<Props> { | |
throw new Error(resp.data.message) | ||
} | ||
|
||
this.props.router.push(`/signin`) | ||
router.push(`/signin`) | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
handleSignOut() | ||
}, []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
return null | ||
} | ||
|
||
export default withRouter<Props>(Logout) | ||
export default ErrorHandling(withRouter<WithRouterProps>(Logout)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import AJAX from 'src/utils/ajax' | ||
import {Authorization} from 'src/types' | ||
import {Authorization, Auth0Config} from 'src/types' | ||
|
||
export const createAuthorization = async ( | ||
authorization | ||
|
@@ -17,3 +17,16 @@ export const createAuthorization = async ( | |
throw error | ||
} | ||
} | ||
|
||
export const getAuth0Config = async (): Promise<Auth0Config> => { | ||
try { | ||
const {data} = await AJAX({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you doubling down on using the old request library for new features? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a great question. I did a global search of influxdb for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
method: 'GET', | ||
url: '/api/v2private/oauth/clientConfig', | ||
}) | ||
return data | ||
} catch (error) { | ||
console.error(error) | ||
throw error | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ import { | |
Panel, | ||
SelectGroup, | ||
} from '@influxdata/clockface' | ||
import auth0js from 'auth0-js' | ||
import auth0js, {WebAuth} from 'auth0-js' | ||
|
||
// Components | ||
import {LoginForm} from 'src/onboarding/components/LoginForm' | ||
|
@@ -25,17 +25,10 @@ import {GoogleLogo, GithubLogo} from 'src/clientLibraries/graphics' | |
// Types | ||
import {Auth0Connection, FormFieldValidation} from 'src/types' | ||
|
||
// Actions | ||
// APIs & Actions | ||
import {notify} from 'src/shared/actions/notifications' | ||
import {passwordResetSuccessfully} from 'src/shared/copy/notifications' | ||
|
||
// TODO: these are filler properties that will be populated on IDPE in a later iteration | ||
const auth0 = new auth0js.WebAuth({ | ||
domain: 'www.influxdata.com', | ||
clientID: 'abc123', | ||
redirectUri: 'www.influxdata.com', | ||
responseType: 'code', | ||
}) | ||
import {getAuth0Config} from 'src/authorizations/apis' | ||
|
||
interface ErrorObject { | ||
[key: string]: string | undefined | ||
|
@@ -61,6 +54,8 @@ interface State { | |
} | ||
|
||
class LoginPageContents extends PureComponent<DispatchProps> { | ||
private auth0?: typeof WebAuth | ||
|
||
state: State = { | ||
activeTab: 'login', | ||
buttonStatus: ComponentStatus.Default, | ||
|
@@ -76,6 +71,16 @@ class LoginPageContents extends PureComponent<DispatchProps> { | |
confirmPasswordError: '', | ||
} | ||
|
||
public async componentDidMount() { | ||
const config = await getAuth0Config() | ||
this.auth0 = auth0js.WebAuth({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dope |
||
domain: config.domain, | ||
clientID: config.clientID, | ||
redirectUri: config.redirectURL, | ||
responseType: 'code', | ||
}) | ||
} | ||
|
||
render() { | ||
const { | ||
buttonStatus, | ||
|
@@ -273,7 +278,7 @@ class LoginPageContents extends PureComponent<DispatchProps> { | |
this.setState({buttonStatus: ComponentStatus.Loading}) | ||
|
||
if (activeTab === 'login') { | ||
auth0.login( | ||
this.auth0.login( | ||
{ | ||
realm: Auth0Connection.Authentication, | ||
email, | ||
|
@@ -289,7 +294,7 @@ class LoginPageContents extends PureComponent<DispatchProps> { | |
return | ||
} | ||
|
||
auth0.signup( | ||
this.auth0.signup( | ||
{ | ||
connection: Auth0Connection.Authentication, | ||
email, | ||
|
@@ -304,7 +309,7 @@ class LoginPageContents extends PureComponent<DispatchProps> { | |
return | ||
} | ||
// log the user into Quartz | ||
auth0.login( | ||
this.auth0.login( | ||
{ | ||
realm: Auth0Connection.Authentication, | ||
email, | ||
|
@@ -346,7 +351,7 @@ class LoginPageContents extends PureComponent<DispatchProps> { | |
} | ||
|
||
private handleSocialClick = (connection: Auth0Connection) => { | ||
auth0.authorize({ | ||
this.auth0.authorize({ | ||
connection, | ||
}) | ||
} | ||
|
@@ -358,7 +363,7 @@ class LoginPageContents extends PureComponent<DispatchProps> { | |
this.setState({emailError: 'Please enter a valid email address'}) | ||
return | ||
} | ||
auth0.changePassword( | ||
this.auth0.changePassword( | ||
{ | ||
email, | ||
connection: Auth0Connection.Authentication, | ||
|
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.
you need some more types in here. try running this in
influxdb/ui
:yarn tsc -noImplicitAny | grep -A 3 -i "$(git diff --name-status master | awk '{ print substr($2,4) }')