do not use PORTAL_DOMAIN for api requests

This commit is contained in:
Karol Wypchlo 2022-03-18 16:45:01 +01:00
parent f47bd3f9a4
commit 1822814441
No known key found for this signature in database
GPG Key ID: B515DE9EEBE241E1
3 changed files with 3 additions and 9 deletions

View File

@ -1,5 +1,3 @@
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: `${prefix}/api` });
export default ky.create({ prefixUrl: "/api" });

View File

@ -2,8 +2,6 @@ import useSWR from "swr";
import { useRouter } from "next/router";
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) => {
return fetch(url).then((res) => {
if (res.status === StatusCodes.UNAUTHORIZED) {
@ -17,5 +15,5 @@ const fetcher = (url, router) => {
export default function useAccountsApi(key, config) {
const router = useRouter();
return useSWR(`${prefix}/api/${key}`, (url) => fetcher(url, router), config);
return useSWR(`/api/${key}`, (url) => fetcher(url, router), config);
}

View File

@ -2,8 +2,6 @@ import useSWR from "swr";
import { useRouter } from "next/router";
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) => {
return fetch(url).then((res) => {
if (res.status === StatusCodes.OK) router.push("/");
@ -13,5 +11,5 @@ const fetcher = (url, router) => {
export default function useAnonRoute() {
const router = useRouter();
return useSWR(`${prefix}/api/user`, (url) => fetcher(url, router));
return useSWR("/api/user", (url) => fetcher(url, router));
}