So here is my issue. I have a main application which has devise in it,for which I am creating an engine. In the engine I need the current_user from main app. Not sure how I will get that, I tried this link but to no avail. Any help would be great. If this is not recommended please do explain why.
Solved it
In the engine you can access the main app using 'main_app'. In this variable you have access to the current user, assuming you have devise. In order to access devise current_user all you have to do is
main_app.scope.env['warden'].user
Devise stores the user inside warden key in the session. Since it uses warden internally to authenticate and store the details in session.
If there is an alternative solution please do let me know.
If you are using Rails 5.1+ this would instead be
main_app.scope.request.env['warden'].user
Thats because env has been deprecated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With