Signing out

To sign a user out, we use the signOut function returned from withDoormanUser or useDoormanUser.

For a full walkthrough of these functions, see accessing the current user.

Example

React Hooks
Higher Order Component
Class Components
React Hooks
import React from 'react'
import { Text } from 'react-native'
import { useDoormanUser } from 'react-native-doorman'
const UserDetails = () => {
const { signOut } = useDoormanUser()
return <Text onPress={signOut}>Sign Out!</Text>
}
export default UserDetails
Higher Order Component
import React from 'react'
import { Text } from 'react-native'
import { withDoormanUser } from 'react-native-doorman'
function UserDetails(props) {
// receives a user prop
const { signOut } = props.user
return <Text onPress={signOut}>Sign Out!</Text>
}
export default withDoormanUser(UserDetails)
Class Components
import React from 'react'
import { Text } from 'react-native'
import { withDoormanUser } from 'react-native-doorman'
class UserDetails extends React.Component {
render() {
// access via this.props.user
const { signOut } = this.props.user
return <Text onPress={signOut}>Sign Out!</Text>
}
}
export default withDoormanUser(UserDetails)

withDoormanUser and useDoormanUser should only be used on screens that show up after a user has signed in. If you use either one in a component when the user hasn't authenticated yet, it will throw an error.