Updated api fetch to return an object.

This commit is contained in:
Mike Cao 2020-09-30 15:14:44 -07:00
parent e64b35f701
commit e5cd162b83
10 changed files with 28 additions and 28 deletions

View file

@ -31,19 +31,19 @@ export default function LoginForm() {
const [message, setMessage] = useState();
const handleSubmit = async ({ username, password }) => {
const response = await post('/api/auth/login', { username, password });
const { ok, status, data } = await post('/api/auth/login', { username, password });
if (typeof response !== 'string') {
if (ok) {
await Router.push('/');
} else {
setMessage(
response.startsWith('401') ? (
status === 401 ? (
<FormattedMessage
id="message.incorrect-username-password"
defaultMessage="Incorrect username/password."
/>
) : (
response
data
),
);
}