You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In SolidStart, if i use server action, how can I do the same thing in ExpressJS:
Set cookies in response headers.
Returns the response status code along with the data.
According to the Returning responses topic, I also tried Response.json() and json() and throw redirect( "/path" ), but none of these worked.
On Github and Stack Overflow, I've seen many people mention createCookieSessionStorage, but now when I search the SolidStart documentation I can't find it anywhere. So, what is its replacement?
// src/actions/auth/index.tsx"use server";import{flatten,safeParse}from"valibot";import{SignInSchema}from"./schema";importdbConnect,{GetUserModel}from"@/libs/mongodb";exporttypeSignInResponseType={status: ""|"success"|"fail",message: string,error: {email: string,password: string}};constSignInServerAction=async(formData: FormData)=>{try{constdata: {[key: string]: FormDataEntryValue;}=Object.fromEntries(formData.entries()),result=safeParse(SignInSchema,data);if(result.success){awaitdbConnect();constUserModel=GetUserModel();constsearchUser=awaitUserModel.findOne({email: data.email.toString().trim()});if(!searchUser){consterrorResponse: SignInResponseType={status: "fail",message: "Email or password is incorrect",error: {email: "",password: ""}};returnerrorResponse;// <-- Currently I only return data}constsuccessResponse: SignInResponseType={status: "success",message: "Signing succeeded",error: {email: "",password: ""}};returnsuccessResponse;// <-- Currently I only return data}else{constissues=flatten<typeofSignInSchema>(result.issues),errorResponse: SignInResponseType={status: "fail",message: "Please provide complete information",error: {email: issues.nested?.email?.[0]||"",password: issues.nested?.password?.[0]||""}};returnerrorResponse;// <-- Currently I only return data}}catch(error){consterrorResponse: SignInResponseType={status: "fail",message: "Internal Server Error",error: {email: "",password: ""}};returnerrorResponse;// <-- Currently I only return data}};export{SignInServerAction};
And BTW, in Sessions topic, I understand its purpose, but the examples are really difficult to understand/visualize. Can I get more specific explanations and instructions?
Anyone please help me. I'm stuck with this for 3 days. Thanks in advance.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
In SolidStart, if i use server action, how can I do the same thing in ExpressJS:
According to the Returning responses topic, I also tried
Response.json()
andjson()
andthrow redirect( "/path" )
, but none of these worked.On Github and Stack Overflow, I've seen many people mention createCookieSessionStorage, but now when I search the SolidStart documentation I can't find it anywhere. So, what is its replacement?
And BTW, in Sessions topic, I understand its purpose, but the examples are really difficult to understand/visualize. Can I get more specific explanations and instructions?
Anyone please help me. I'm stuck with this for 3 days. Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions