russellchoudhury
russellchoudhury
SSolidJS
Created by russellchoudhury on 10/22/2024 in #support
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
1 replies
SSolidJS
Created by russellchoudhury on 10/20/2024 in #support
Can I nest cache functions
Can I nest cache functions and does it prevent multiple calls to the db, for instance
export const getAuthCache = cache(async () => {
'use server'

return getAuth()
}, 'getAuthCache')

export const requireAuthCache = cache(async () => {
'use server'

const auth = await getAuthCache()
if (!auth?.user) {
throw redirect('/auth/signin?error=unauthorized')
}
return auth
}, 'requireAuthCache')

export const getAccountCache = cache(async () => {
'use server'
const auth = await requireAuthCache()
return getAccountById(auth.session.selectedAccountId)
}, 'getAccountCache')
export const getAuthCache = cache(async () => {
'use server'

return getAuth()
}, 'getAuthCache')

export const requireAuthCache = cache(async () => {
'use server'

const auth = await getAuthCache()
if (!auth?.user) {
throw redirect('/auth/signin?error=unauthorized')
}
return auth
}, 'requireAuthCache')

export const getAccountCache = cache(async () => {
'use server'
const auth = await requireAuthCache()
return getAccountById(auth.session.selectedAccountId)
}, 'getAccountCache')
do i get the benefits of cache from the above code?
7 replies
SSolidJS
Created by russellchoudhury on 10/10/2024 in #support
Random Crashes when redirecting via middleware
On dev i will get regular crashes with the below error when redirecting via the middleware Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
4 replies
SSolidJS
Created by russellchoudhury on 9/3/2024 in #support
SSG/SSR on specific paths for landing page
My main web app has SSR set to false, I would like my landing page to be SSG (or SSR) for SEO purposes, how can I achieve this in one solid start app here is my current app.config.ts
import { defineConfig } from '@solidjs/start/config'
import { cloudflare } from 'unenv'

export default defineConfig({
vite: () => ({
build: {
target: 'es2020',
},
}),
server: {
preset: 'cloudflare-pages',
unenv: cloudflare,
rollupConfig: {
external: ['__STATIC_CONTENT_MANIFEST', 'node:async_hooks'],
},
prerender: {
routes: ['/'],
ignore: ['/app/*', '/auth/*', '/api/*'],
},
},
middleware: './src/middleware.ts',
ssr: false,
})
import { defineConfig } from '@solidjs/start/config'
import { cloudflare } from 'unenv'

export default defineConfig({
vite: () => ({
build: {
target: 'es2020',
},
}),
server: {
preset: 'cloudflare-pages',
unenv: cloudflare,
rollupConfig: {
external: ['__STATIC_CONTENT_MANIFEST', 'node:async_hooks'],
},
prerender: {
routes: ['/'],
ignore: ['/app/*', '/auth/*', '/api/*'],
},
},
middleware: './src/middleware.ts',
ssr: false,
})
20 replies
SSolidJS
Created by russellchoudhury on 8/26/2024 in #support
"use server" working locally but not when deployed
why does this code not work when deployed but works locally in dev? removing "use server" makes it work but for some reason when its there my output is just "Signed in as" logs also do not show that getAuth is running register.tsx
import { createAsync } from "@solidjs/router";
import { getAuth } from '~/lib/server/auth'


export default function Register() {
const auth = createAsync(() => getAuth(), { deferStream: true })

return (
<p>Signed in as {auth()?.user.email}</p>
)
}
import { createAsync } from "@solidjs/router";
import { getAuth } from '~/lib/server/auth'


export default function Register() {
const auth = createAsync(() => getAuth(), { deferStream: true })

return (
<p>Signed in as {auth()?.user.email}</p>
)
}
~/lib/server/auth
import { cache } from "@solidjs/router";

export const getAuth = cache(async () => {
"use server"

console.log("getAuth")
return {
user: {
}
}
}, 'getAuth')
import { cache } from "@solidjs/router";

export const getAuth = cache(async () => {
"use server"

console.log("getAuth")
return {
user: {
}
}
}, 'getAuth')
--- deployed on cloudflare
server: {
preset: 'cloudflare-pages',
unenv: cloudflare,

rollupConfig: {
external: ['__STATIC_CONTENT_MANIFEST', 'node:async_hooks'],
},
},
middleware: './src/middleware.ts',
ssr: false,
server: {
preset: 'cloudflare-pages',
unenv: cloudflare,

rollupConfig: {
external: ['__STATIC_CONTENT_MANIFEST', 'node:async_hooks'],
},
},
middleware: './src/middleware.ts',
ssr: false,
16 replies