diff --git a/frontend/app/components/Login/Login.tsx b/frontend/app/components/Login/Login.tsx index eec61d02e..15e51c194 100644 --- a/frontend/app/components/Login/Login.tsx +++ b/frontend/app/components/Login/Login.tsx @@ -10,7 +10,7 @@ import { toast } from 'react-toastify'; import { ENTERPRISE_REQUEIRED } from 'App/constants'; import { useStore } from 'App/mstore'; import { forgotPassword, signup } from 'App/routes'; -import { fetchTenants, login, setJwt } from 'Duck/user'; +import { fetchTenants, loginSuccess, setJwt } from 'Duck/user'; import { Button, Form, Icon, Input, Link, Loader, Tooltip } from 'UI'; import Copyright from 'Shared/Copyright'; @@ -24,7 +24,7 @@ interface LoginProps { errors: any; // Adjust the type based on your state shape loading: boolean; authDetails: any; // Adjust the type based on your state shape - login: typeof login; + loginSuccess: typeof loginSuccess; setJwt: typeof setJwt; fetchTenants: typeof fetchTenants; location: Location; @@ -34,7 +34,7 @@ const Login: React.FC = ({ errors, loading, authDetails, - login, + loginSuccess, setJwt, fetchTenants, location, @@ -99,13 +99,17 @@ const Login: React.FC = ({ }; const handleSubmit = (token?: string) => { - login({ email: email.trim(), password, 'g-recaptcha-response': token }); loginStore.setEmail(email.trim()); loginStore.setPassword(password); if (token) { loginStore.setCaptchaResponse(token); } - void loginStore.generateSpotJWT((jwt) => handleSpotLogin(jwt)); + loginStore.generateJWT().then((resp) => { + if (resp) { + handleSpotLogin(resp.spotJwt); + } + loginSuccess(resp) + }) }; const onSubmit = (e: React.FormEvent) => { @@ -286,7 +290,7 @@ const mapStateToProps = (state: any, ownProps: any) => ({ }); const mapDispatchToProps = { - login, + loginSuccess, setJwt, fetchTenants, }; diff --git a/frontend/app/duck/user.js b/frontend/app/duck/user.js index 24b23f6a4..31db486b7 100644 --- a/frontend/app/duck/user.js +++ b/frontend/app/duck/user.js @@ -126,6 +126,11 @@ export const login = params => ({ call: client => client.post('/login', params) }); +export const loginSuccess = data => ({ + types: LOGIN.SUCCESS, + data +}) + export const signup = params => dispatch => dispatch({ types: SIGNUP.toArray(), call: client => client.post('/signup', params) diff --git a/frontend/app/mstore/loginStore.ts b/frontend/app/mstore/loginStore.ts index 3845bd613..46f05c909 100644 --- a/frontend/app/mstore/loginStore.ts +++ b/frontend/app/mstore/loginStore.ts @@ -58,19 +58,19 @@ class LoginStore { this.spotJwtPending = pending } - generateSpotJWT = async (onSuccess: (jwt:string) => void) => { + generateJWT = async () => { if (this.spotJwtPending) { return } this.setSpotJwtPending(true) try { - const resp = await loginService.spotLogin({ + const resp = await loginService.login({ email: this.email, password: this.password, captchaResponse: this.captchaResponse }) - this.setSpotJWT(resp.jwt) - onSuccess(resp.jwt) + this.setSpotJWT(resp.spotJwt) + return resp } catch (e) { console.error(e) } finally { diff --git a/frontend/app/services/loginService.ts b/frontend/app/services/loginService.ts index 3e3ac6efd..e746eaa78 100644 --- a/frontend/app/services/loginService.ts +++ b/frontend/app/services/loginService.ts @@ -1,8 +1,8 @@ import BaseService from "./BaseService"; export default class LoginService extends BaseService { - public async spotLogin({ email, password, captchaResponse }: { email: string, password: string, captchaResponse?: string }) { - return this.client.post('/spot/login', { + public async login({ email, password, captchaResponse }: { email: string, password: string, captchaResponse?: string }) { + return this.client.post('/login?spot=true', { email: email.trim(), password, 'g-recaptcha-response': captchaResponse,