Cache Auth Wrapper

How can I create a wrapper for the cache/action functions so that they include the auth check? So I'd like to go From
export const getAccountCache = cache(async () => {
'use server'
const auth = await requireAuth()
if (!auth?.user) {
throw redirect('/auth/signin?error=unauthorized')
}
const account = await getAccountById(auth.session.selectedAccountId)
if (!account) {
throw new Error('Account not found')
}
return account
}, 'getAccountCache')
export const getAccountCache = cache(async () => {
'use server'
const auth = await requireAuth()
if (!auth?.user) {
throw redirect('/auth/signin?error=unauthorized')
}
const account = await getAccountById(auth.session.selectedAccountId)
if (!account) {
throw new Error('Account not found')
}
return account
}, 'getAccountCache')
To
export const getAccountCache = cacheWithAuth(async () => {
'use server'
const account = await getAccountById(auth.session.selectedAccountId)
if (!account) {
throw new Error('Account not found')
}
return account
}, 'getAccountCache')
export const getAccountCache = cacheWithAuth(async () => {
'use server'
const account = await getAccountById(auth.session.selectedAccountId)
if (!account) {
throw new Error('Account not found')
}
return account
}, 'getAccountCache')
what would the cacheWithAuth look like
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server