I have a login button in a React component that works perfectly in desktop browsers but not on mobile. I'm finding it hard to debug.
This is the form.
<form className="signin_form" onSubmit={onLogin}>
<label className="sr-only" htmlFor="email"></label>
<input
onChange={(e) => {
setEmail(e.target.value);
}}
className="form_input"
type="text"
name="email"
placeholder="Email"
autoFocus
/>
<label className="sr-only" htmlFor="password"></label>
<input
onChange={(e) => {
setPassword(e.target.value);
}}
className="form_input"
type="password"
name="password"
placeholder="Password"
/>
{error && (
<p className="error error_message">
Username or password is incorrect
</p>
)}
<button type="submit" className="btn btn_primary">
Sign In
</button>
</form>
And here is the function that is called on submit
const onLogin = async (e) => {
e.preventDefault();
try {
const result = await axios.post(`${url}/login`, {
email,
password,
});
dispatch({ type: SET_TOKEN, payload: result.data.token });
if (result.data.status === 1) {
const newData = await axios.get(`${url}/syncStore`, {
headers: { token: result.data.token },
});
dispatch({
type: UPDATE_STORE,
payload: newData.data,
});
navigate("/dashboard");
} else {
showError();
}
} catch (error) {
console.log(error);
}
};
Any help greatly appreciated
The button call the backend api and check creds. Then log in the user. It just won't work on mobile.
I've tested on Safari, Chrome and Firefox