Comments (11)
Removed Auth.auth().currentUser
from the top variables. Not sure how that would cause a crash on another page but okay then. We're back in business.
from thrivechurchofficialapp.
@suttonau @Ndk1996 Thanks for your comments. Interesting that @Ndk1996 I didn't see your comment until now.
So when I think about why this might happen (I'm not 100% sure why either). I think this line
let currentUserId = Auth.auth().currentUser?.uid
(still happens with var
too) is an invalid variable declaration because it cannot retrieve currentUser?.uid
. This is because if there is no user logged in the uid will be nil
. Now that wouldn't necessarily cause a crash, by assigning nil to a variable. It will if you're using currentUserId
for something.
But I think ultimately the reason that this happens is because the global variable created is attempting to make this reference to currentUser
before the app can use handle
to check if the user is logged in, using something like line 11 and following:
// global vars
fileprivate var handle: AuthStateDidChangeListenerHandle?
var user: User? // not sure if this is required but it might be helpful to refer to the User as just user
// inside either viewDidLoad or ViewDidAppear
// Listen for Auth State changes
self.handle = Auth.auth().addStateDidChangeListener(self.handleAuthStateChanged(auth:user:))
// Check status of user
func handleAuthStateChanged(auth: Auth, user: User?) {
if Auth.auth().currentUser != nil {
// User is signed in.
}
else {
// Login OR Register -- only if their email is not already in Auth
}
}
Once this runs we have the ability to reference anything under Auth.Auth().currentUser
. Also, the code block above can happen on another thread so there's no way of knowing exactly when this will run. So what I would recommend is include a check in the AppDelegate
. Or inside your View Controller that you're using currentUser?.uid
. Making this a local variable solves this issue for this reason. I'd imagine that perhaps using this (might?) work filepriveate currentUserId = Auth.auth().currentUser?.uid
. But I doubt it.
Hopefully that helps you guys a little bit with understanding how this happens. Then again that's just what makes sense to me. I could be wrong.
from thrivechurchofficialapp.
@ksigWyatt Thanks a lot!!
It helped me solve the problem.
from thrivechurchofficialapp.
Removed
Auth.auth().currentUser
from the top variables. Not sure how that would cause a crash on another page but okay then. We're back in business.
!! Thank you very much dr @ksigWyatt !!
from thrivechurchofficialapp.
I have the same bug but I dont have any Auth.auth().currentUser variable on top sir
from thrivechurchofficialapp.
@ksigWyatt Same for me - Everything was working fine but then I made a global variable let currentUserId = Auth.auth().currentUser?.uid
and then the app started crashing. Just moved the variable inside my one of my methods and everything is fine now. Thanks for your help I didn't know what was causing the error for a while. I wonder why it does this?
from thrivechurchofficialapp.
I experienced the same issue with the Auth variable. I wanted to access it globally so I created a global variable for it var user = Auth.auth().currentUser
- This caused my app to crash.
from thrivechurchofficialapp.
Im experiencing the same issue when trying to connect sign in button to tab bar view controller
I fixed it redirecting the segway to another view.
from thrivechurchofficialapp.
Even my app is crashing!! How can I access the Auth variable globally? Any help will be appreciated.
from thrivechurchofficialapp.
@nikhilagr It seems as though you cannot access this globally. You must assign it to a value whenever you want to use it.
What I'd recommend is something like this:
- Declare a global variable outside your
init
/viewDidLoad
method - Assign this nullable variable a default value of
nil
so you should have something like thisvar currentUser: User? = nil
- Within your init / viewDidLoad method, assign the current user to your global variable via something like this
self.currentUser = Auth.auth().currentUser
.- NOTE: Assuming that a user is currently logged in, this value will contain something other than nil. You could put a breakpoint here just to verify yourself that this in fact works as we expect.
- Anyplace within your view controller you need to use the current user. Simply use
self.currentUser
.- Now, there is no guarantee that
self.currentUser
will continue to hold this value. If the user is logged out ourself.currentUser
may return to nil. Because we are creating a reference type; See more on 'Deep Copy vs Shallow Copy'
- Now, there is no guarantee that
So I would expect this to work, where you can access self.currentUser
within a view controller. You (May?) be able to get away with passing it around to other View Controllers within a DidSet
block, but again if the user logs out, then this value will have changed.
from thrivechurchofficialapp.
@nikhilagr No problem. I'm glad I could help you
from thrivechurchofficialapp.
Related Issues (20)
- Migrate from UIWebView to WKWebView
- User Accounts
- Prayer Wall
- Making Values Configurable HOT 1
- 1.7.4 Bug Fixes
- Convert table view controllers to be Dynamic
- Convert table view controllers to be Dynamic
- Ability to listen to bible passage
- Check config values each time the page loads not on app launch
- Add dark mode support via iOS settings
- Mailchimp / newsletter RSS integration
- Add an AppClip for Donations / Widgets HOT 1
- Users with no recently played see no series graphic when playing from watch history
- Add timer to the time we go live
- Reset notification counter when ever the application launches
- Sermon Video Downloads HOT 1
- Application crashes when downloading the same audio file more than once
- Watch / Listen progression
- Update Recently Played to remove all recently played if Message ID is type GUID
- V2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thrivechurchofficialapp.