do not use PORTAL_DOMAIN for api requests
This commit is contained in:
parent
f47bd3f9a4
commit
1822814441
|
@ -1,5 +1,3 @@
|
||||||
import ky from "ky";
|
import ky from "ky";
|
||||||
|
|
||||||
const prefix = process.env.NEXT_PUBLIC_PORTAL_DOMAIN ? `https://account.${process.env.NEXT_PUBLIC_PORTAL_DOMAIN}` : "";
|
export default ky.create({ prefixUrl: "/api" });
|
||||||
|
|
||||||
export default ky.create({ prefixUrl: `${prefix}/api` });
|
|
||||||
|
|
|
@ -2,8 +2,6 @@ import useSWR from "swr";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { StatusCodes } from "http-status-codes";
|
import { StatusCodes } from "http-status-codes";
|
||||||
|
|
||||||
const prefix = process.env.NEXT_PUBLIC_PORTAL_DOMAIN ? `https://account.${process.env.NEXT_PUBLIC_PORTAL_DOMAIN}` : "";
|
|
||||||
|
|
||||||
const fetcher = (url, router) => {
|
const fetcher = (url, router) => {
|
||||||
return fetch(url).then((res) => {
|
return fetch(url).then((res) => {
|
||||||
if (res.status === StatusCodes.UNAUTHORIZED) {
|
if (res.status === StatusCodes.UNAUTHORIZED) {
|
||||||
|
@ -17,5 +15,5 @@ const fetcher = (url, router) => {
|
||||||
export default function useAccountsApi(key, config) {
|
export default function useAccountsApi(key, config) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
return useSWR(`${prefix}/api/${key}`, (url) => fetcher(url, router), config);
|
return useSWR(`/api/${key}`, (url) => fetcher(url, router), config);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@ import useSWR from "swr";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { StatusCodes } from "http-status-codes";
|
import { StatusCodes } from "http-status-codes";
|
||||||
|
|
||||||
const prefix = process.env.NEXT_PUBLIC_PORTAL_DOMAIN ? `https://account.${process.env.NEXT_PUBLIC_PORTAL_DOMAIN}` : "";
|
|
||||||
|
|
||||||
const fetcher = (url, router) => {
|
const fetcher = (url, router) => {
|
||||||
return fetch(url).then((res) => {
|
return fetch(url).then((res) => {
|
||||||
if (res.status === StatusCodes.OK) router.push("/");
|
if (res.status === StatusCodes.OK) router.push("/");
|
||||||
|
@ -13,5 +11,5 @@ const fetcher = (url, router) => {
|
||||||
export default function useAnonRoute() {
|
export default function useAnonRoute() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
return useSWR(`${prefix}/api/user`, (url) => fetcher(url, router));
|
return useSWR("/api/user", (url) => fetcher(url, router));
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue