change login request url to include spot param
This commit is contained in:
parent
d46d7e8b36
commit
70ceb220f0
4 changed files with 21 additions and 12 deletions
|
|
@ -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<LoginProps> = ({
|
|||
errors,
|
||||
loading,
|
||||
authDetails,
|
||||
login,
|
||||
loginSuccess,
|
||||
setJwt,
|
||||
fetchTenants,
|
||||
location,
|
||||
|
|
@ -99,13 +99,17 @@ const Login: React.FC<LoginProps> = ({
|
|||
};
|
||||
|
||||
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<HTMLFormElement>) => {
|
||||
|
|
@ -286,7 +290,7 @@ const mapStateToProps = (state: any, ownProps: any) => ({
|
|||
});
|
||||
|
||||
const mapDispatchToProps = {
|
||||
login,
|
||||
loginSuccess,
|
||||
setJwt,
|
||||
fetchTenants,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue