Skip to content

Commit

Permalink
import router in client.ts (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
caleballdrin authored Sep 23, 2024
1 parent a536cc4 commit 6c1e09f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
7 changes: 1 addition & 6 deletions pages/_app.page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextPage } from 'next';
import type { AppProps } from 'next/app';
import Head from 'next/head';
import { useRouter } from 'next/router';
import React, { ReactElement, useMemo } from 'react';
import { ApolloProvider } from '@apollo/client';
import createEmotionCache from '@emotion/cache';
Expand Down Expand Up @@ -59,11 +58,7 @@ const GraphQLProviders: React.FC<{
children: React.ReactNode;
}> = ({ children = null }) => {
const { apiToken } = useRequiredSession();
const { replace } = useRouter();
const client = useMemo(
() => makeClient(apiToken, replace),
[apiToken, replace],
);
const client = useMemo(() => makeClient(apiToken), [apiToken]);

return (
<ApolloProvider client={client}>
Expand Down
6 changes: 3 additions & 3 deletions src/lib/apollo/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router } from 'next/router';
import router from 'next/router';
import { ApolloClient, from } from '@apollo/client';
import { onError } from '@apollo/client/link/error';
import { LocalStorageWrapper, persistCache } from 'apollo3-cache-persist';
Expand All @@ -25,7 +25,7 @@ if (typeof window !== 'undefined' && process.env.NODE_ENV === 'production') {
});
}

const makeClient = (apiToken: string, routerReplace: Router['replace']) => {
const makeClient = (apiToken: string) => {
const client = new ApolloClient({
link: from([
makeAuthLink(apiToken),
Expand All @@ -47,7 +47,7 @@ const makeClient = (apiToken: string, routerReplace: Router['replace']) => {
.then((response) => {
// eslint-disable-next-line no-console
console.log('Incorrect accountListId provided. Redirecting.');
routerReplace(
router.replace(
replaceUrlAccountList(
window.location.pathname,
response.data.user.defaultAccountList,
Expand Down

0 comments on commit 6c1e09f

Please sign in to comment.