Skip to content

Commit

Permalink
Fix WPCC redirect (#3281)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebykat authored Jan 6, 2025
1 parent 00a9aa1 commit cf9c7cb
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type Props = OwnProps;

export class Auth extends Component<Props> {
state = {
authState: '',
isCreatingAccount: false,
passwordErrorMessage: null,
onLine: window.navigator.onLine,
Expand Down Expand Up @@ -543,7 +542,6 @@ export class Auth extends Component<Props> {

onSubmitCode = (event: React.FormEvent) => {
event.preventDefault();
this.setState({ authState: 'login-requested' });
this.setState({
passwordErrorMessage: '',
});
Expand All @@ -564,8 +562,8 @@ export class Auth extends Component<Props> {

onWPLogin = () => {
const redirectUrl = encodeURIComponent(config.wpcc_redirect_url);
this.setState({ authState: `app-${cryptoRandomString(20)}` });
const authUrl = `https://public-api.wordpress.com/oauth2/authorize?client_id=${config.wpcc_client_id}&redirect_uri=${redirectUrl}&response_type=code&scope=global&state=${this.state.authState}`;
const savedAuthState = `app-${cryptoRandomString(20)}`;
const authUrl = `https://public-api.wordpress.com/oauth2/authorize?client_id=${config.wpcc_client_id}&redirect_uri=${redirectUrl}&response_type=code&scope=global&state=${savedAuthState}`;

window.electron.send('wpLogin', authUrl);

Expand Down Expand Up @@ -596,7 +594,7 @@ export class Auth extends Component<Props> {
return this.authError('An error was encountered while signing in.');
}

if (authState !== this.state.authState) {
if (authState !== savedAuthState) {
return;
}
this.props.tokenLogin(userEmail, simperiumToken);
Expand Down

0 comments on commit cf9c7cb

Please sign in to comment.