-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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) }')