#Remix-Auth commiting the cookie session

1 messages · Page 1 of 1 (latest)

timid hamlet
#

Hello! I was using the remix-auth for the authorization in my remix application. i am getting the accessToken,refreshToken and expiresAt from the microsoft-auth strategy. when the token gets expired i am using the refresh token to get the updated accessToken and commiting it to the remix session cookies. But the commit session is not updating the session with updated token. can anyone know why commitSession is not updating the session

Here is an example code of how i am commiting the session in while fetching using refreshToken

timid imp
#

commitSession returns a string that you need to use as the value of the Set-Cookie header in the response you sent to the browser

#

without that, the commitSession will return the string and do nothing else

timid hamlet
#

can you tell me how can i use that string to be updated in the browser cookies?

timid imp
#
return redirect("/", {
  headers: { "Set-Cookie": await commitSession(session) },
});
#

it doesn't need to be a redirect response, it works with json too, the important part is the set-cookie header

timid hamlet
#

Hi i updated the code to use "Set-Cookie" for commit session

But still it is not updated in the browser cookies and the request as well

timid imp
#

is this json response the one you sent from your loader or action?

timid hamlet
#

Nope it is in the authenticate function that we get the token

timid imp
#

you need to send the response to the browser

#

you do that by returning it on the loader or action

#

this is similar to what you did before, you're creating the Response object now (the same way you created the string from commitSession) but you're doing nothing with it

#

one thing you could do is to pass a Headers object from the loader/action to your refreshToken function

#

then use that headers instance in your loader/action

timid hamlet
#

Ok i got it It is working now