1

I'm making a web app: Angular in front-end and Rails in back-end. When User signs up, I redirect them to Angular html routes using below function:

  def after_inactive_sign_up_path_for(resource)
    '/info-page'
  end

In application controller, I render below function to check which template to render. If user is not logged in, I render home.html.erb. If user is logged in, I render Angular templates:

def home
    if current_user
        render :file => 'public/front-end/public/index.html', :layout => false and return
    else
        render :file => '/static_pages/home.html.erb'
    end
end

And I set `Application#home' as root page in Rails like following way:

root 'application#home'

The problem occurs after the user signs up at the very first time of using my web app. I send out email confirmation email after user signs up so when they are redirected to /info-page, they are not successfully logged in yet so in Application#home, it falls under else statement and renders '/static_pages/home.html.erb'. If I want to successfully load /info-page, I need to render the other file because that file loads Angular.

So here is a question. After user signs up, current_user is nil. Is there any way to check any information related to user after they sign up?

JoHksi
  • 517
  • 1
  • 7
  • 26
  • Are you using tokens or sessions to authenticate the user? – Graham S. Jun 05 '16 at 04:13
  • devise has a method named `confirmed?`. Use that one for the last signed up user. – Emu Jun 05 '16 at 04:17
  • @GrahamS., not sure what you really mean. I just use normal Devise gem to handle all user related stuff. – JoHksi Jun 05 '16 at 04:19
  • 1
    @Emu, do you mean I need to find the last signed up user and check confirmed? But what if another user signs up a second after i signed up and the other user becomes the last person? I think this works but it is a bit hacky. – JoHksi Jun 05 '16 at 04:21
  • @JoHksi, Yes that's what I mean. It would not be a problem if simultaneous users got signed up as the action will be called each time after a user got signed up. I don't know if there's a better solution is present or not. – Emu Jun 05 '16 at 04:30
  • @Emu, how do you think about using cookie? I can add certain value to cookie when user signs up, and deletes that value when it is confirmed. – JoHksi Jun 05 '16 at 04:32
  • @JoHksi, that's the same problem again. Anyone can find user's cookies easily. – Emu Jun 05 '16 at 04:35
  • @Emu, isn't cookie saved locally in user's machine? Can you explain further why it is a same problem again? I think it will not cause any problem if I do `cookie[:user_signed_up] = true` after user model is made and do `delete cookie[:user_signed_up]` after user signs for the first time. – JoHksi Jun 05 '16 at 04:39
  • @JoHksi, Check this one: http://stackoverflow.com/questions/9223555/devise-with-confirmable-redirect-user-to-a-custom-page-when-users-tries-to-sig#9224409 – Emu Jun 05 '16 at 04:40
  • @Emu, That's a fabulous answer, but I still face a problem in `Application#home`. I need to render `index.html` when the user is signed up but not when authenticated. Your provided link does not solve this issue :(. I just need to somehow render `index.html` when user is made but not authenticated yet. – JoHksi Jun 05 '16 at 04:58
  • I think you're looking for redirect after signup: https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-up-(registration) – seph Jun 05 '16 at 05:46
  • @seph, the problem is not redirection. The problem is that, I somehow need to access newly signed up user information and check whether it is authenticated yet or not. However, I do not know how to access newly signed up user information in a correct manner now. – JoHksi Jun 05 '16 at 08:01

0 Answers0