I have a fairly basic and rudimentary forum that I’ve made only accessible to logged in and verified users. However, when someone wants to open a post in a new tab, it kicks them off saying they’re either not logged in or unverified. Here’s some code:
Meteor.user() is reactive so the user might not have loaded yet when you do the user check. If you want your router to handle auth logic then you’ll likely want to wrap your Meteor.user() check in a Tracker.autorun (you might also want to add in a Meteor.loggingIn() check).
Just as an aside - FlowRouter recommends using template level auth handling for a few reasons, one of which is this exact issue (having to wait for data to be ready in the router doesn’t necessarily provide the best user experience). See the Implementing Auth Logic and Permissions section of Kadira’s Routing Guide for more info.
Hmmm. The suggested method above doesn’t seem to work for me.
I’m getting the following errors (as an example):
Uncaught TypeError: Cannot read property '__reactInternalInstance$tj2hftd5sqxfcmdpxjldz33di' of null
Any idea what this means? Also getting this just above:
TypeError: Cannot read property '_currentElement' of null
I’m assuming it’s trying to load the page before it’s got all the necessary information through props (it only does it on pages like a forum post or whatever). I’m not savvy enough to figure out a solution myself though. So further help will be excellent.
Note that this doesn’t have the method mentioned in the Kadira post above because it makes no difference. If I do it the same way @arunoda suggests it reacts in the same way. Maybe it’s react-mounter?
Thanks for those links. The first one (regarding setState) doesn’t seem to apply in my case. I’m not passing any state with the code I showed above as it’s a ‘static’ page with content coming from mongo.
The second one has a few issues in there, but again can’t pinpoint the error I’m getting. If I have a properly defined route, such as /forums or /games with no props to pass down, the url works fine and I can open in new tab without issues.
It’s only when I want something like /forums/:_id or /games/:slug that I have a problem. Unfortunately, as we know this is a key part of the app… It’s really frustrating. It also means prerender isn’t caching my pages. Sad times
It’s worth mentioning if you go to the pages while using the app itself, it works no problem. So if I’m sat on the homepage and click the link to a forum post or game page (in the case of this app) then it works without issue. It’s like it can’t get what it needs when re-opening the connection or something. Definitely related to Tracker in someway as well though:
The full error I get when accessing a ‘Games’ page with open in new tab is:
Uncaught TypeError: Cannot read property 'cover' of undefined
Uncaught TypeError: Cannot read property '__reactInternalInstance$3uv0xozwusgcsl0ag5z1vy4x6r' of null
Exception from Tracker recompute function:
TypeError: Cannot read property '_currentElement' of null
at R._updateRenderedComponent (28d96c6….js?meteor_js_resource=true:32)
at R._performComponentUpdate (28d96c6….js?meteor_js_resource=true:32)
at R.updateComponent (28d96c6….js?meteor_js_resource=true:32)
at R.performUpdateIfNecessary (28d96c6….js?meteor_js_resource=true:32)
at Object.s.performUpdateIfNecessary (28d96c6….js?meteor_js_resource=true:28)
at u (28d96c6….js?meteor_js_resource=true:28)
at o.r.perform (28d96c6….js?meteor_js_resource=true:28)
at r.perform (28d96c6….js?meteor_js_resource=true:28)
at r.p.perform (28d96c6….js?meteor_js_resource=true:28)
at Object.D [as flushBatchedUpdates] (28d96c6….js?meteor_js_resource=true:28)
I just had a fiddle around with it again this morning. Then I realised the router wasn’t in the lib directory (for some reason) and was instead in the client directory. Moving it into lib has fixed the open in new tab issues!
So in the end, completely my own fault. However, probably worth remembering and keeping this thread alive in case anyone else comes across this problem themselves.