Skip to content

Commit

Permalink
refactor(session): remove sessionKey prop and generate key internally (
Browse files Browse the repository at this point in the history
  • Loading branch information
ertugrulcan-ays authored Jan 8, 2025
2 parents bb1aba2 + d5512b8 commit d5e2898
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
2 changes: 0 additions & 2 deletions apps/web/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ export default async function RootLayout({
const session = await auth();
const grantedPolicies = session?.grantedPolicies;

const sessionKey = new Date().valueOf();
return (
<html className="h-full overflow-hidden" lang={lang}>
<body className={GeistSans.className} data-app-name={appName}>
<Providers
grantedPolicies={grantedPolicies}
lang={lang}
session={session}
sessionKey={sessionKey}
>
{children}
</Providers>
Expand Down
4 changes: 1 addition & 3 deletions apps/web/src/providers/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ interface ProvidersProps {
children: JSX.Element;
lang: string;
grantedPolicies: Record<Policy, boolean> | undefined;
sessionKey: number;
session: Session | null;
}
export default async function Providers({
children,
lang,
grantedPolicies,
sessionKey,
session,
}: ProvidersProps) {
const resources = await getLocalizationResources(lang);
Expand All @@ -31,7 +29,7 @@ export default async function Providers({
<>
<Toaster richColors />
<ApplicationProvider appName={appName}>
<SessionProvider session={session} sessionKey={sessionKey}>
<SessionProvider session={session}>
<GrantedPoliciesProvider grantedPolicies={grantedPolicies}>
<ConfigProvider>
<Tooltip>
Expand Down
11 changes: 3 additions & 8 deletions apps/web/src/providers/session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { createContext, useContext, useMemo } from "react";
interface ProvidersProps {
children: React.ReactNode;
session: Session | null;
sessionKey?: number;
}
interface SessionContextProps {
session: Session | null;
Expand All @@ -19,14 +18,10 @@ export const useSession = () => {
return useContext(SessionContext);
};

export function SessionProvider({
children,
session,
sessionKey,
}: ProvidersProps) {
export function SessionProvider({ children, session }: ProvidersProps) {
const memoizedSessionKey = useMemo(() => {
return sessionKey;
}, [sessionKey]);
return new Date().valueOf();
}, [session]);
return (
<SessionContext.Provider key={memoizedSessionKey} value={{ session }}>
{children}
Expand Down

0 comments on commit d5e2898

Please sign in to comment.