cyu / rack-cors

Rack Middleware for handling Cross-Origin Resource Sharing (CORS), which makes cross-origin AJAX possible.
MIT License
3.27k stars 263 forks source link

Rails 7 and ros-apartment login logout set up #237

Closed martinbarilik closed 2 years ago

martinbarilik commented 2 years ago

I have recently updated to rails 7 and i got into point i can't solve the CORS problem when logging in and out in development env.

Using latest devise, rails and ros-apartment. I have a database of tenants with names containing number which behaves as subdomain.

When i am logging in i am at "http://eu.development:3000", clickcing "LOG IN" buttton should redirect me to appropriate subdomain, let's call it "5119583939", new url should look like 'http://5119583939.eu.development:3000" but whatever setting i make i am getting:

Access to fetch at 'http://5119583939.eu.development:3000/' (redirected from 'http://eu.development:3000/users/sign_in') from origin 'http://eu.development:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. application.debug-bab306102c8c5004d7dc7e599ac0b372da2e1afec8892a6ce6ec0243cf5622ea.js:5667 GET http://5119583939.eu.development:3000/ net::ERR_FAILED 401

edit: when i F5 the page, i am logged in ( which is weird to me, but OK )

When i log out the situation is the same but going from "http://5119583939.eu.development:3000/" to "http://eu.development:3000/"

i even found this https://github.com/cyu/rack-cors/issues/30 but with no luck

How am i supposed to allow this redirections ? Thanks for any help

martinbarilik commented 2 years ago

I just found out, it's a issue with devise i am using.

https://gorails.com/episodes/devise-hotwire-turbo?autoplay=1

rack-cors working as intened