fix: Signup from OAuth not being detected correctly (#37697)

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: d53fcdf0451a5911471b05678e03831a0d9a632a
> <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 -->
This commit is contained in:
Shrikant Sharat Kandula 2024-11-26 12:22:43 +05:30 committed by GitHub
parent 1295c6ac63
commit 5cfe143b86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -252,8 +252,7 @@ public class AuthenticationSuccessHandlerCE implements ServerAuthenticationSucce
// 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.
@ -270,19 +269,20 @@ public class AuthenticationSuccessHandlerCE implements ServerAuthenticationSucce
.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
@ -290,6 +290,7 @@ public class AuthenticationSuccessHandlerCE implements ServerAuthenticationSucce
webFilterExchange, defaultWorkspaceId, authentication, isFromSignup, createDefaultApplication);
}
final boolean isFromSignupFinal = isFromSignup;
Mono<Void> finalRedirectionMono = redirectionMono;
return sessionUserService
.getCurrentUser()
@ -307,7 +308,7 @@ public class AuthenticationSuccessHandlerCE implements ServerAuthenticationSucce
modeOfLogin = ((OAuth2AuthenticationToken) authentication).getAuthorizedClientRegistrationId();
}
if (isFromSignup) {
if (isFromSignupFinal) {
final String inviteToken = currentUser.getInviteToken();
final boolean isFromInvite = inviteToken != null;