# Undefined Method Refresh Token in AuthenticatedSystem

**URL:** <https://www.ruby-forum.com/t/undefined-method-refresh-token-in-authenticatedsystem/180024>\
**Category:** Rails\
**Created:** [December 9, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/undefined-method-refresh-token-in-authenticatedsystem/180024 "2009-12-09T22:30:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [December 9, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/undefined-method-refresh-token-in-authenticatedsystem/180024/1 "2009-12-09T22:30:57Z")

</div>

On my site, I have a series of protected tabs and a series of public  
tabs. Depending on the level of authentication, the tabs are viewable  
to specific groups. I’ve encountered an old issue and I feel it’s time  
to correct this problem. I’ve put it off for sometime now, and while  
that’s not the best thing to do, I had a simple workaround in place.

The issue starts in the application controller through these lines here:

def get\_user\_tabs  
if logged\_in? && User.find(current\_user).admin?  
@tabs = Page.find\_main  
else  
@tabs = Page.find\_main\_public  
end  
end

I use AuthenticatedSystem with activation for my site. If I login with  
a specific admin group and check “remember me”, each subsequent visit  
for the next week I’ll automatically be logged in.

However, the very first time I hit the website, I’ll receive the  
following error:

NoMethodError (undefined method `refresh\_token’ for #User:0x5ffe238)

The refresh\_token in AuthenticatedSystem usually corresponds to the  
remember\_me token setting. I believe what’s happening is that the token  
isn’t being refreshed until after the second page click on the site  
occurs. Therefore, it will error out as per above.

I’ve gotten around this issue by doing the following rescue:

def get\_user\_tabs  
begin  
if logged\_in? && User.find(current\_user).admin?  
@tabs = Page.find\_main  
else  
@tabs = Page.find\_main\_public  
end  
rescue  
logger.error(“undefined method `refresh\_token”)  
@tabs = Page.find\_main\_public  
end  
end

However, as you can see, I should not have to place a rescue in and the  
corrupted data should not be allowed to reach as far as the rescue,  
IMHO. I’ve searched many areas in AuthenticatedSystem from issues, to  
wiki, etc. but can’t seem to pinpoint where this issue might be stemming  
from. Perhaps it’s as simple as how I find the current user?

Any help on this matter would be appreciated.

Thanks.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [December 9, 2009, 10:41pm UTC](https://www.ruby-forum.com/t/undefined-method-refresh-token-in-authenticatedsystem/180024/2 "2009-12-09T22:41:03Z")

</div>

As a further diagraming mode for this problem above, using the rescue  
workaround that I have in place:

First visit to the site with remember\_me active as an administrator:

[publictab1] [publictab2] [publictab3] [publictab4]

Tabs correspond to menu buttons…

The login shows that I’m logged in as an administrator. However, I only  
see public tabs (menu buttons).

On the very next click (on any public tab), I see the following:

[publictab1] [publictab2] [publictab3] [PRIVATETAB1] [PRIVATETAB2]  
[publictab4]

So, what is happening is the first visit to the site causes the rescue  
to force display public tabs only and then I have to click a tab in  
order to see the private tabs as well as the public tabs. I believe it  
might have something to do with the way the remember me token is  
refreshed…

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [December 11, 2009, 11:28pm UTC](https://www.ruby-forum.com/t/undefined-method-refresh-token-in-authenticatedsystem/180024/3 "2009-12-11T23:28:41Z")

</div>

I waited a couple of days before bumping this. I could still use some  
help on this. If any further information is needed, please let me know.

Thanks.
