zakpatterson
zakpatterson
SSolidJS
Created by zakpatterson on 9/15/2024 in #support
SolidStart - proper `_server` form action urls are only on page refresh.
I think I figured this out, while trying to make a reproduction, but I don't entirely understand what is happening. I'm making actions like this:
const withUser = async <A>(f: (user: User) => A): Promise<A> => {
const session = await getSession()
const userId = session.data.userId
const user = await db.lookupUser(userId)
if(user === undefined) throw "not allowed" // 401 error or whatever
return f(user)
})

export const updateUserProfile = action(async (formData): Promise<User> => {
'use server'
return withUser((currentUser) => {
//do update
const updatedUser = db.updateUser(currentUser.id, userFromFormData(formData))
return updatedUser
})
})
const withUser = async <A>(f: (user: User) => A): Promise<A> => {
const session = await getSession()
const userId = session.data.userId
const user = await db.lookupUser(userId)
if(user === undefined) throw "not allowed" // 401 error or whatever
return f(user)
})

export const updateUserProfile = action(async (formData): Promise<User> => {
'use server'
return withUser((currentUser) => {
//do update
const updatedUser = db.updateUser(currentUser.id, userFromFormData(formData))
return updatedUser
})
})
It seems the 'use server' comment is required on the withUser function above, as well. But I don't quite get why. Why would it be required there but not on the db function calls? @Madaxen86 and anyone that sees this. Thank you!
4 replies
SSolidJS
Created by zakpatterson on 9/15/2024 in #support
SolidStart - proper `_server` form action urls are only on page refresh.
Let me know if my mistake seems obvious or I'll try to make a reproduction
4 replies