Giter VIP home page Giter VIP logo

Comments (4)

anthonyflores-github avatar anthonyflores-github commented on May 29, 2024

Hello,
have you found the solution?
I'm also looking for how to disconnect.

from react-native-firebase.

moafzalmulla avatar moafzalmulla commented on May 29, 2024

So I saw a stack overflow saying I should use redux, then came across a documentation saying redux is ok for state, but not Navigation state.

I wrote a logout function as:
const onLogoutButtonPress = () => { // navigation.navigate('Login'); firebase .auth() .signOut() .then(() => { console.log("USER LOGGED IN !!!: " + JSON.stringify(user)) setUser(null) console.log("USER LOGGED OUT !!!: " + JSON.stringify(user)) // navigation.navigate('Login')} // navigation.navigate( // 'Home', // {}, // NavigationActions.navigate({ // routeName: 'HomeScreen' // }) // ) }) .catch(error => { alert(error) }) }

That logs out user, but doesnt re-render app.js which houses user auth logic.

I looked react navigation documentation, but to no avail. Maybe I missed something

Some sources say you can use NavigationActions , as navigation is not available for use as navigation.navigate('Login')}

That said I passed navigation as a prop and it was empty. Thats because navigation.navigate() is only available to navigate to pages within the stack.

In our case, HomeScreen is in one stack and Login + Registration is in another stack. So we cannot move up from stack to stack.

But I wonder if we put all of them in the same stack, then navigation.navigate() will work right and being a mobile app, the user wont be able to navigate to the page without a button provided by us ? ....hmmm this just came to me #rubberDuckTheory .. I will test and get back to you guys.

PS. I am not using redux for this, but might keep it in to manage other all round state bits.

If any one else gets a solution, do post #happyLockdownCoding

Mo

from react-native-firebase.

moafzalmulla avatar moafzalmulla commented on May 29, 2024

UPDATE:

So I did 2 things and I think it works.

  1. add a copy of Login and Registration components in Logged in NavigationStack:
    Screenshot 2020-11-27 at 18 18 16

  2. Add this logout function:
    Screenshot 2020-11-27 at 18 18 34

It seems to now be logging out for me and loads the component as the Login and Registration components are now in the stack. By the time it calls that component firebase .signOut() has already run

So in effect, you wont be logged in anymore

Try and let me know

Hope this helps

@mrcflorian Thank you for this awesome repo. Will be good to hear your thoughts.

Sources: https://reactnavigation.org/docs/stack-actions/

from react-native-firebase.

PingOfD32th avatar PingOfD32th commented on May 29, 2024

code

this should work for any future googlers. setting setUser to null triggers a rerender and thus you to automatically go to the login screen, so there is no need to redirect explicitly (unless you wanted to make a "logged out" screen).

from react-native-firebase.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.