avoid too many duplicate requireUserInServerComponent requests for each page+layout
This commit is contained in:
@@ -140,7 +140,7 @@ async function analysisPackagesWithVariantLoader({
|
||||
}
|
||||
|
||||
async function analysisPackagesLoader() {
|
||||
const account = await loadCurrentUserAccount();
|
||||
const { account } = await loadCurrentUserAccount();
|
||||
if (!account) {
|
||||
throw new Error('Account not found');
|
||||
}
|
||||
|
||||
@@ -16,9 +16,12 @@ export const loadUserAccount = cache(accountLoader);
|
||||
|
||||
export async function loadCurrentUserAccount() {
|
||||
const user = await requireUserInServerComponent();
|
||||
return user?.id
|
||||
? await loadUserAccount(user.id)
|
||||
: null;
|
||||
const userId = user?.id;
|
||||
if (!userId) {
|
||||
return { account: null, user: null };
|
||||
}
|
||||
const account = await loadUserAccount(userId);
|
||||
return { account, user };
|
||||
}
|
||||
|
||||
async function accountLoader(userId: string) {
|
||||
|
||||
Reference in New Issue
Block a user