Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
how to set more than one cookie in sveltekit endpoint response?

I'm using sveltekit set-cookie in an endpoint but I'm unable to figure out how to set more than one cookie. I get three cookies back from expressjs server. I need to set the three of them in my endpoint.

I have this endpoint in sveltekit that fetch from an expressjs

import cookie from 'cookie';
export async function post (event) {
    
    const info = await event.request.json()
      let email = info.name
      let password = info.password
      let fetchresults = ""
    
  //fetch from expressjs//
const letscookie = async () => {
      
      let res = await fetch('http://localhost:3000/testcookie',{
            method: 'POST',          
            credentials : 'include',
          headers: {
            'Accept': 'application/json',
            'Content-type' : 'application/json',
           
          },
           body: JSON.stringify({
               username : email,
               password : password
           })
      }) 

      const data = await res.json()   
      fetchresults = data
      return data   

    } 
    let cookieresults = await letscookie()


  return {
  headers : {
      "loginjs-cookieone" : fetchresults.accesstoken,
       "loginjs-cookietwo" : fetchresults.refreshtoken,
      "x-custom-header": "Whatever",          
      'set-cookie': cookie.serialize("loginjs", " setcookie_in_loginjs_headers")    
  },     
  body : {
       //passthistofront,
       //results,
       cookieresults
      
  }

}

}

My question is how to setup more than one cookie in my headers? if I do

headers : {
          "loginjs-cookieone" : fetchresults.accesstoken,
           "loginjs-cookietwo" : fetchresults.refreshtoken,
          "x-custom-header": "Whatever",          
          'set-cookie': cookie.serialize("loginjs", " setcookie_in_loginjs_headers"),
'set-cookie' : [cookie.serealize("cookieone", "valueone"), cookie.serealize("cookietwo", "valuetwo")]  
      },  

I get the last cookie set and anything before it is ignored or over written. So how do I set more than one cookie in my headers using set-cookie?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I removed other set-cookie lines. Just one set-cookie and put the cookies in an array like this

'set-cookie' : [cookie.serealize("cookieone", "valueone"), cookie.serealize("cookietwo", "valuetwo")] 

One set-cookie in headers.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!