Important things to know when creating authorization with sessions
When creating authorization, there are some important setup steps to make sure that your sessions save.
The backend setup is crucial if you want to be able to save your sessions.
Cors: Make sure that you have enabled the cors gem and also set up cors.rb
It is important to make sure that “credentials” are true.
You also need to make sure that your application.rb file is set up
The important lines of code are lines 25, 26, 30, and 33. Lines 25 and 26 must be above 30 and 33.
Make sure to create your session routes and create your session controller.
Your session custom routes will need to be a post and a destroy.
post ‘/login’, to: ‘sessions#create’
delete ‘/logout’, to: ‘sessions#destroy’
In the sessions controller your create method will look something like this
On your front-end, you will need to use withCredentials: true in your fetches
With this set up, you should be able to refresh the page and stay logged in