You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When first signing in, everything works fine. However, if the application starts with a user previously logged in, and therefore Auth.signed_in? = true, then Auth.current_user must be set as it is currently false.
I check for this and set it in app_delegate:
app_delegate.rb
def on_load(app, options)
if Auth.signed_in?
ApiClient.update_authorization_header(Auth.authorization_header)
if Auth.current_user.nil?
set_current_user
mp Auth.current_user # evaluates to nil !!!
end
open_authenticated_root
else
open SignInScreen.new(nav_bar: true)
end
end
def open_authenticated_root
open_tab_bar MatchesScreen.new(nav_bar: true), MatchTemplatesScreen.new(nav_bar: true)
end
def set_current_user
ApiClient.client.get "user" do |response|
if response.success?
Auth.current_user = User.new(response.object["data"])
else
app.alert "Please sign in again"
open SignInScreen.new(nav_bar: true)
end
end
end
The problem is that despite setting Auth.current_user this way, it is always nil when evaluating right away and is also nil in the authenticated_root screen. It does return the User object just fine in the REPL though. I don't know what I'm doing wrong.
The text was updated successfully, but these errors were encountered:
I'm so sorry that I didn't reply until now. I'm assuming you already figured it out, or found a workaround, but I can see the issue in your code. You are not waiting for the HTTP request to be returned. In your code you have:
ifAuth.current_user.nil?set_current_usermpAuth.current_user# evaluates to nil !!!end
But that's because your set_current_user method is going to run asynchronously. If I were you, I would rewrite this method to accept a block:
ifAuth.current_user.nil?set_current_userdompAuth.current_user# shouldn't be nilendend# ...defset_current_user(&success_callback)ApiClient.client.get"user"do |response|
ifresponse.success?Auth.current_user=User.new(response.object["data"])success_callback.callelseapp.alert"Please sign in again"openSignInScreen.new(nav_bar: true)endendend
I am having issues with setting .current_user
When first signing in, everything works fine. However, if the application starts with a user previously logged in, and therefore Auth.signed_in? = true, then Auth.current_user must be set as it is currently false.
I check for this and set it in app_delegate:
app_delegate.rb
The problem is that despite setting Auth.current_user this way, it is always nil when evaluating right away and is also nil in the authenticated_root screen. It does return the User object just fine in the REPL though. I don't know what I'm doing wrong.
The text was updated successfully, but these errors were encountered: