# Authlogic and Aegis, current\_user nil problem, Guest user

**URL:** <https://www.ruby-forum.com/t/authlogic-and-aegis-current-user-nil-problem-guest-user/184831>\
**Category:** Rails\
**Created:** [March 9, 2010, 10:15am UTC](https://www.ruby-forum.com/t/authlogic-and-aegis-current-user-nil-problem-guest-user/184831 "2010-03-09T10:15:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![analogue40](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e8cbc/32.png) [@analogue40](https://www.ruby-forum.com/u/analogue40)\
**Post date:** [March 9, 2010, 10:15am UTC](https://www.ruby-forum.com/t/authlogic-and-aegis-current-user-nil-problem-guest-user/184831/1 "2010-03-09T10:15:12Z")

</div>

Hi All,

I have set up Authlogic and Aegis for role based authorization.

Each time I check if a user has permission to do something, as it  
stands now I have to check ‘current\_user’ isn’t empty first, like  
this:

\<% if current\_user and current\_user.may\_do\_something? %\>

I’d like to change it so that if the user isn’t logged in, an empty  
user is created with the role of ‘guest’, an like explained in this  
post:

> **[Aegis: Role-based Permissions for your Ruby on Rails application](https://agileweboperations.com/2009/07/05/role-based-permissions-for-your-ruby-on-rails-application/)**
>
> This is a guest post by our friends over at makandra, a cool Ruby on Rails development shop. Today they announce a great new Ruby gem for dealing with role-based permissions. You know the game! Eac…

@current\_user = User.find\_by\_id(session[“user\_id”]) ||  
User.new(:role\_name =\> “guest”)

The problem is that I have no idea how to implement this in Authlogic,  
the application controller has these two methods, can anyone help out?

def current\_user\_session  
return @current\_user\_session if defined?(@current\_user\_session)  
@current\_user\_session = UserSession.find  
end

```
def current_user
  return @current_user if defined?(@current_user)
  @current_user = current_user_session &&

```

current\_user\_session.user  
end

Thanks in advance!
