Support basePath in all queries.

This commit is contained in:
Mike Cao 2020-09-30 22:34:16 -07:00
parent 2508198a51
commit 5068ab12a9
11 changed files with 57 additions and 29 deletions

View file

@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';
import { Formik, Form, Field } from 'formik';
import Router from 'next/router';
import { useRouter } from 'next/router';
import { post } from 'lib/web';
import Button from 'components/common/Button';
import FormLayout, {
@ -28,13 +28,17 @@ const validate = ({ username, password }) => {
};
export default function LoginForm() {
const router = useRouter();
const [message, setMessage] = useState();
const handleSubmit = async ({ username, password }) => {
const { ok, status, data } = await post('/api/auth/login', { username, password });
const { ok, status, data } = await post(`${router.basePath}/api/auth/login`, {
username,
password,
});
if (ok) {
await Router.push('/');
return router.push('/');
} else {
setMessage(
status === 401 ? (