Closed Ragudos closed 9 months ago
I believe the issue is you don't have a secret key configured, so when restarting the server a new key is generated, which causes decryption to fail on your old cookies.
You are using .get_private()
and the logs show:
>> secret key: [generated]
Warning: secrets enabled without a stable `secret_key`
>> disable `secrets` feature or configure a `secret_key`
>> this becomes an error in non-debug profiles
The solution would be to specify a key in your Rocket.toml. I use openssl rand -base64 32
to generate my keys, I'm not sure if that works on windows.
[default]
secret_key = "MnNHJCt69yU7xdyCiExtT1vto6geQ6Xd2VDpaD9AZx0="
Oh, I see! I thought the warning about secrets was related to the .env variables. I'll try it out and close this issue. Thank you!
Rocket Version
0.5.0
Operating System
Windows 10 Pro v.21H1 64-bit OS build: 19043.1826
Rust Toolchain Version
1.75.0
What happened?
I have a simple web server with my own login functionality. It adds a private cookie once the credentials match what the database has. I am at the beginning stages of this project, so I restart the server every time I make a change since I have not enabled hot reload yet. However, after reloading, it seems that the get methods are not reading the cookie. I printed the contents of the request and it's there as well as in the browser.
Test Case
Log Output
Additional Context
I do not know if it is an intended behavior (maybe there is a memory storage of cookies and that is why it is gone on server restart?). I am new to Rust and Rocket, so pardon me if this Issue is not of importance. Thank you.
Here's the main rs file:
and the forwarding to see if a user exists when an endpoint requires it as a parameter:
Steps to reproduce (since Idk how to test):
You'll see that you'll get redirected and the return type of the get methods are None, but the cookie exists when it's printed out.
Additionally, other cookies (added on the browser) gets read successfully. For example. theme cookie with the key of "theme" gets read properly even after server restart.
System Checks
rustc
toolchain.