meteorrn / meteor-react-native

Meteor client for React Native matching Meteor Spec
https://guide.meteor.com/react-native.html
Other
59 stars 31 forks source link

Calling Meteor.logout() results an error #21

Closed NickTheTurtle closed 4 years ago

NickTheTurtle commented 4 years ago

Describe the bug Calling Meteor.logout results an error.

To Reproduce Call Meteor.logout() in project. User is logged out though. See screenshot below.

Expected behavior User is logged out. No error.

Screenshots The error below shows that this.handleLogout is not defined.

image

Device (please complete the following information):

TheRealNate commented 4 years ago

Hi @NickTheTurtle. Thanks for posting! I can't seem to reproduce the issue. I am testing on the same React Native and MeteorRN versions as you.

Any chance you could share the full error message and stacktrace?

If you have a chance, these further measures may help diagnose the issue:

NickTheTurtle commented 4 years ago

Thanks for the quick reply! Here's the more detailed error message. I'll try reinstalling MeteorRN and clearing the build folder.

image
TheRealNate commented 4 years ago

Hi @NickTheTurtle, any updates on this?

NickTheTurtle commented 4 years ago

It still doesn't work. I decided to console.log(Object.getOwnPropertyNames(this)) just before this.handleLogout(), and this is the output:

["process", "__BUNDLE_START_TIME__", "undefined", "NaN", "__DEV__", "Infinity", "isNaN", "isFinite", "escape", "unescape", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "eval", "globalThis", "parseInt", "parseFloat", "ArrayBuffer", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "Proxy", "Reflect", "JSON", "Math", "console", "Int8Array", "Int16Array", "Int32Array", "Uint8Array", "Uint8ClampedArray", "Uint16Array", "Uint32Array", "Float32Array", "Float64Array", "DataView", "Date", "Error", "Boolean", "Map", "Number", "Set", "Symbol", "WeakMap", "WeakSet", "Object", "Function", "Array", "RegExp", "String", "Intl", "__jsiExecutorDescription", "nativeModuleProxy", "nativeFlushQueueImmediate", "nativeCallSyncHook", "globalEvalWithSourceUrl", "nativeLoggingHook", "nativePerformanceNow", "__r", "__d", "__c", "__registerSegment", "$RefreshReg$", "$RefreshSig$", "__accept", "originalConsole", "ErrorUtils", "GLOBAL", "window", "self", "performance", "__fbBatchedBridge", "__fbGenNativeModule", "originalPromise", "originalRegeneratorRuntime", "regeneratorRuntime", "setInterval", "clearInterval", "requestIdleCallback", "cancelIdleCallback", "XMLHttpRequest", "FormData", "fetch", "Headers", "Request", "Response", "File", "FileReader", "URL", "URLSearchParams", "AbortController", "AbortSignal", "alert", "navigator", "__fetchSegment", "__getSegment", "setTimeout", "clearTimeout", "setImmediate", "clearImmediate", "__REACT_DEVTOOLS_GLOBAL_HOOK__", "__blobCollectorProvider", "Blob", "Trackr", "requestAnimationFrame", "cancelAnimationFrame", "REACT_NAVIGATION_REDUX_DEVTOOLS_EXTENSION_INTEGRATION_ENABLED", "UserFeedScreen", "Tabs", "Promise", "WebSocket"]

TheRealNate commented 4 years ago

Hmm, it seems like this is evaluating to the global object. This is really strange behavior (could also be related to your other issue #22).

Do you have anything that could be changing how this is being bound?

TheRealNate commented 4 years ago

I just did some testing in the console. If you'd like, you can try changing the syntax:

From:

logout() {

}

To:

logout:function () {

}

Both should work, but it couldn't hurt trying.

NickTheTurtle commented 4 years ago

You're right. I had <Button onPress={Meteor.logout}>Logout</Button>, but React bound this to the global object instead of Meteor. I changed it to <Button onPress={Meteor.logout.bind(Meteor)}>Logout</Button> and now everything works perfectly.

Thanks for helping me!

TheRealNate commented 4 years ago

Hi @NickTheTurtle, thanks for providing your solution! I'm going to see if there is a way to fix this. If its not too much of an inconvenience, could you try something like this (which is how I have it in my apps), where Meteor logout is called from inside a function?:

// For class Component (<Button onPress={this.logout}>)
logout = () => {
    Meteor.logout();
}

// For function components (<Button onPress={logout}>)
const logout = () => {
    Meteor.logout()
}
TheRealNate commented 4 years ago

Hey @NickTheTurtle, one last thing. I've just published 2.0.10-beta1 which converts it from an object to a class. If its not too much of an inconvenience, could you try installing that version then using it the original way you were (<Button onPress={Meteor.logout}>)