refactor(app): scope heavy providers to authenticated route layouts
This commit is contained in:
31
app/(app)/layout.tsx
Normal file
31
app/(app)/layout.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import * as Sentry from "@sentry/nextjs";
|
||||
|
||||
import { InitUser } from "@/components/init-user";
|
||||
import { AppProviders } from "@/components/providers";
|
||||
import { getAuthUser, getToken } from "@/lib/auth-server";
|
||||
|
||||
export default async function AuthenticatedAppLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const initialToken = await getToken();
|
||||
const user = await getAuthUser();
|
||||
|
||||
if (user) {
|
||||
const id = user.userId ?? String(user._id);
|
||||
Sentry.setUser({
|
||||
id,
|
||||
email: user.email ?? undefined,
|
||||
});
|
||||
} else {
|
||||
Sentry.setUser(null);
|
||||
}
|
||||
|
||||
return (
|
||||
<AppProviders initialToken={initialToken}>
|
||||
<InitUser />
|
||||
{children}
|
||||
</AppProviders>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user