Skip to content

Commit 3e17b2c

Browse files
authored
Remove generator default overriding navigational_formats (#515)
`config/initializers/devise.rb` sets `navigational_formats` twice. An earlier line sets it to `[]` (alongside `skip_session_storage = [:http_auth, :token_auth]`), which is the intended API-only behaviour. The generator's stock block further down then overrides it with `["*/*", :html]`. With `*/*` treated as navigational, Devise's failure app takes the redirect branch on auth failure. On GET requests it calls `store_location!`, which writes to the session - disabled on this app - raising `DisabledSessionError`. So a GET auth failure without a JSON `Accept` header returns 500 instead of 401. POST failures return 302 (no session write, since `store_location!` only stores on GET). Not reachable from the SPA, which sends `Accept: application/json` and gets 401 as expected. Surfaced via curl. **Change:** delete the duplicate assignment and its boilerplate comment, leaving `[]` as the effective value. No sign-in page exists on this API-only backend to redirect to. **Verified on UAT:** locked account with a valid token, `GET /users`, no `Accept` header - 500 (`DisabledSessionError`) before, 401 after. JSON `Accept` path unchanged. **Note:** the 401 now carries `content-type: */*; charset=utf-8` (echoing `request.format`). Cosmetic - body is still JSON. Independent of #508/#512; branched off `sg-dev`.
1 parent c5902a4 commit 3e17b2c

1 file changed

Lines changed: 0 additions & 11 deletions

File tree

config/initializers/devise.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,6 @@
231231
# only the current scope. By default, Devise signs out all scopes.
232232
# config.sign_out_all_scopes = true
233233

234-
# ==> Navigation configuration
235-
# Lists the formats that should be treated as navigational. Formats like
236-
# :html, should redirect to the sign in page when the user does not have
237-
# access, but formats like :xml or :json, should return 401.
238-
#
239-
# If you have any extra navigational formats, like :iphone or :mobile, you
240-
# should add them to the navigational formats lists.
241-
#
242-
# The "*/*" below is required to match Internet Explorer requests.
243-
config.navigational_formats = ["*/*", :html]
244-
245234
# The default HTTP method used to sign out a resource. Default is :delete.
246235
config.sign_out_via = :delete
247236

0 commit comments

Comments
 (0)