From de26d43e17b3285b02dc62acd513a4cd544e4841 Mon Sep 17 00:00:00 2001 From: Bruno Papista <78353799+papistacoding@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:47:42 +0100 Subject: [PATCH] Feat await gql client (#152) * fixing google and github signin * remove clg * await gql client * adding comment --- apps/console/src/app/providers.tsx | 25 +++++++++++++++++++++++-- apps/console/src/middleware.ts | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/apps/console/src/app/providers.tsx b/apps/console/src/app/providers.tsx index 87be86b7..725cc314 100644 --- a/apps/console/src/app/providers.tsx +++ b/apps/console/src/app/providers.tsx @@ -7,19 +7,26 @@ import { useSession } from 'next-auth/react' import { ThemeProvider } from '@/providers/theme' import { usePathname } from 'next/navigation' import { ReactNode, useEffect, useState } from 'react' +import { Loading } from '@/components/shared/loading/loading' interface ProvidersProps { children: ReactNode } +//IF YOU ADD PUBLIC PAGE, ITS REQUIRED TO CHANGE IT IN middleware.tsx +const publicPages = ['/login', '/verify', '/resend-verify', '/waitlist', '/invite'] + const Providers = ({ children }: ProvidersProps) => { const { data: session, status } = useSession() const pathname = usePathname() const [client, setClient] = useState(null) const [accessToken, setAccessToken] = useState(null) + const isPublicPage = publicPages.includes(pathname) + useEffect(() => { const tokenChanged = session?.user.accessToken && session?.user.accessToken !== accessToken + if (status === 'authenticated' && tokenChanged) { setAccessToken(session?.user.accessToken) setClient(createClient(session)) @@ -28,11 +35,25 @@ const Providers = ({ children }: ProvidersProps) => { } }, [session?.user.accessToken, status, pathname, accessToken]) - if (status === 'loading' || (status === 'authenticated' && !client)) return null + if (status === 'loading') { + return + } + + if (isPublicPage) { + return ( + + {children} + + ) + } + + if (!client) { + return + } return ( - {client ? {children} : children} + {children} ) } diff --git a/apps/console/src/middleware.ts b/apps/console/src/middleware.ts index b713502e..d460f68a 100644 --- a/apps/console/src/middleware.ts +++ b/apps/console/src/middleware.ts @@ -58,6 +58,8 @@ export const config = { * - waitlist (waitlist page) * - invite (invite verify page) */ + + //IF YOU ADD PUBLIC PAGE, ITS REQUIRED TO CHANGE IT IN Providers.tsx '/((?!api|[_next/static]|[_next/image]|favicon.ico|backgrounds|backgrounds/|icons|icons/|login|verify|resend-verify|waitlist|invite).*)', ], }