Skip to content

Authenticating using Clearance or DIY

losingle edited this page Jun 8, 2015 · 4 revisions

If you are not using devise/warden - and using clearance/DIY, you won't have access to a current_user helper. You'll need to access the authenticated user through the session (or the env variable if you're using Clearance >= 0.13.0).

Clearance Example

The follow example uses the env variable to get the authenticated user.

config/initializers/doorkeeper.rb

resource_owner_authenticator do
  @user = env[:clearance].current_user
   
  unless @user
    session[:return_to] = request.fullpath
    redirect_to(sign_in_url)
  end
  
  @user
end

app/views/layouts/doorkeeper.html.erb

<html>
  ...
  <div id="current_user"><%= @user.username %></div>
  ...
</html>
You can’t perform that action at this time.