Skip to content

Commit

Permalink
fix: Signup from OAuth not being detected correctly (appsmithorg#37697)
Browse files Browse the repository at this point in the history
Fixes issue where the detection for signup when using OAuth was not
being handled correctly.

[Slack
conversation](https://theappsmith.slack.com/archives/C02K2MZERSL/p1732600773587469?thread_ts=1732554015.110689&cid=C02K2MZERSL).


## Automation

/test sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!WARNING]
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12024883331>
> Commit: d53fcdf
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12024883331&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: @tag.Sanity
> Spec: 
> It seems like **no tests ran** 😔. We are not able to recognize it,
please check <a
href="https://github.com/appsmithorg/appsmith/actions/runs/12024883331"
target="_blank">workflow here</a>.
> <hr>Tue, 26 Nov 2024 06:16:02 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Improved handling of user authentication success, enhancing the flow
for email verification and OAuth2 authentication.
- **Refactor**
	- Simplified the logic for determining user sign-up or login status.
- Streamlined the method for handling OAuth2 redirects, improving
clarity and maintainability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
sharat87 authored Nov 26, 2024
1 parent 1295c6a commit 5cfe143
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ public Mono<Void> onAuthenticationSuccess(
// creation) or if this was a login (existing user). What we do here to identify this, is an approximation.
// If and when we find a better way to do identify this, let's please move away from this approximation.
// If the user object was created within the last 5 seconds, we treat it as a new user.
final boolean oauthIsFromSignup =
user.getCreatedAt().isAfter(Instant.now().minusSeconds(5));
isFromSignup = user.getCreatedAt().isAfter(Instant.now().minusSeconds(5));

// Check the existing login source with the authentication source and then update the login source,
// if they are not the same.
Expand All @@ -270,26 +269,28 @@ public Mono<Void> onAuthenticationSuccess(
.subscribeOn(Schedulers.boundedElastic())
.subscribe();
}
if (oauthIsFromSignup) {
if (isFromSignup) {
final boolean isFromSignupFinal = isFromSignup;
redirectionMono = workspaceServiceHelper
.isCreateWorkspaceAllowed(TRUE)
.flatMap(isCreateWorkspaceAllowed -> {
if (isCreateWorkspaceAllowed.equals(Boolean.TRUE)) {
return createDefaultApplication(defaultWorkspaceId, authentication)
.flatMap(application -> handleOAuth2Redirect(
webFilterExchange, application, oauthIsFromSignup));
webFilterExchange, application, isFromSignupFinal));
}
return handleOAuth2Redirect(webFilterExchange, null, oauthIsFromSignup);
return handleOAuth2Redirect(webFilterExchange, null, isFromSignupFinal);
});
} else {
redirectionMono = handleOAuth2Redirect(webFilterExchange, null, oauthIsFromSignup);
redirectionMono = handleOAuth2Redirect(webFilterExchange, null, isFromSignup);
}
} else {
// form type signup/login handler
redirectionMono = formEmailVerificationRedirectionHandler(
webFilterExchange, defaultWorkspaceId, authentication, isFromSignup, createDefaultApplication);
}

final boolean isFromSignupFinal = isFromSignup;
Mono<Void> finalRedirectionMono = redirectionMono;
return sessionUserService
.getCurrentUser()
Expand All @@ -307,7 +308,7 @@ public Mono<Void> onAuthenticationSuccess(
modeOfLogin = ((OAuth2AuthenticationToken) authentication).getAuthorizedClientRegistrationId();
}

if (isFromSignup) {
if (isFromSignupFinal) {
final String inviteToken = currentUser.getInviteToken();
final boolean isFromInvite = inviteToken != null;

Expand Down

0 comments on commit 5cfe143

Please sign in to comment.