How to use devise-guests for having users without signup in Jumpstart?
I tried to add devise-guests, but got stuck. My goal is to allow guests (=users who didn't sign up yet) to try out the application before registering.
I added the devise-guests gem and overrode the current_user method in the ApplicationControler:
# Support guest users everywhere
I added the devise-guests gem and overrode the current_user method in the ApplicationControler:
# Support guest users everywhere
def devise_current_user
@devise_current_user ||= warden.authenticate(scope: :user)
end
def guest_user
guest = super
# Create guest account if guest is new
if guest.accounts.empty?
account = guest.accounts.new(owner: guest, name: guest.email, personal: Jumpstart.config.personal_accounts)
account.account_users.new(user: guest, admin: true)
account.save!
end
guest
end
# Code from https://github.com/cbeer/devise-guests/blob/0a9c0038c5d1d8790907c3bd56cafd0e87525e15/lib/devise-guests/controllers/helpers.rb#L34
def current_user
if devise_current_user
if session[:guest_user_id]
run_callbacks :logging_in_user do
guest_user.destroy unless send(:"skip_destroy_guest_user")
session[:guest_user_id] = nil
end
end
devise_current_user
else
guest_user
end
end
It works in the sense that it creates a guest user and a personal account for them once somebody visits my app. However, this guest user can NOT access any of the routes that are behind an "authenticated" block:
authenticated :user do
It works in the sense that it creates a guest user and a personal account for them once somebody visits my app. However, this guest user can NOT access any of the routes that are behind an "authenticated" block:
authenticated :user do
root to: "dashboard#show", as: :user_root
end
It seems that "authenticated" in routes doesn't use "current_user" and so will not see the guest user.
Is there a way to make guest-users work with Jumpstart?
It seems that "authenticated" in routes doesn't use "current_user" and so will not see the guest user.
Is there a way to make guest-users work with Jumpstart?
Okay, the problem is not particluarly a JSP issue. But accounts and the use of "authenticated" in the routes makes it challenging.
I solved it without the devise-guests gem. Instead I added a warden strategy that creates a fake guest user (just like the gem would). On signup I remove the JSP default account and attach the guests account to the newly registered user instead. Seems to work so far.
If I find time, I might be able to generalize that feature and create a PR. I think, using an app WITHOUT signup is a must-have feature especially if you go with jumpstart-ios (no app store reviewer will forgive you if you make them sign up before using your app!).
I solved it without the devise-guests gem. Instead I added a warden strategy that creates a fake guest user (just like the gem would). On signup I remove the JSP default account and attach the guests account to the newly registered user instead. Seems to work so far.
If I find time, I might be able to generalize that feature and create a PR. I think, using an app WITHOUT signup is a must-have feature especially if you go with jumpstart-ios (no app store reviewer will forgive you if you make them sign up before using your app!).
Notifications
You’re not receiving notifications from this thread.