Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't authenticate user when opening a new download tab #582

Closed
ryankc33 opened this issue Mar 23, 2016 · 1 comment
Closed

can't authenticate user when opening a new download tab #582

ryankc33 opened this issue Mar 23, 2016 · 1 comment

Comments

@ryankc33
Copy link

devise_token_auth doesn't work when opening a new tab to download a file:

Angular app with ng-token-auth

$scope.downloadExcel = (token_id) ->
    $window.open('/excel/download/' + token_id, '_blank', '')
    return true

Rails api controller

class Api::V1::SpreadsheetsController < Api::V1::BaseController
    before_action :authenticate_user!

    respond_to :json, :xlsx

    def download
        @records = Record.where(id: params[:token_id])
        render xlsx: 'excel', filename: 'excel.xlsx', template: "spreadsheets/excel"
    end
end

If I comment out :authenticate_user! in the controller, the code will open a new tab, download an xlsx file, and close as expected. If I don't comment out :authenticate_user!, devise_token_auth returns an unauthorized user error.

How do I authenticate_user in a new download tab?

@ryankc33
Copy link
Author

The problem stems from a conflict within rails routes. Solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant