Skip to content

Commit

Permalink
Add updates to the addition of deleteUser in example app (#6208)
Browse files Browse the repository at this point in the history
  • Loading branch information
elle-j authored and takameyer committed Oct 31, 2023
1 parent 14795a3 commit 6f07e03
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/rn-connection-and-error/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ It specifically addresses the following points:
* With invalid password
* With non-existent email
* Listening (and triggering) when a user gets logged out.
* Listening (and triggering) when a user gets removed.
* Listening (and triggering) when a user's tokens are refreshed.
* Listening (and triggering) when the underlying sync session:
* Tries to connect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import {useCallback, useEffect, useState} from 'react';
import {BSON, ConnectionState, UserState} from 'realm';
import {useRealm, useUser} from '@realm/react';
import {useApp, useRealm, useUser} from '@realm/react';

import {Store} from '../models/Store';
import {logger} from '../utils/logger';
Expand All @@ -37,6 +37,7 @@ let mostRecentAccessToken: string | null = null;
* You can also add a listener to the App (via `useApp()`).
*/
export function useDemoSyncTriggers() {
const app = useApp();
const realm = useRealm();
const currentUser = useUser();
const [isConnected, setIsConnected] = useState(true);
Expand Down Expand Up @@ -147,6 +148,18 @@ export function useDemoSyncTriggers() {
await currentUser.refreshCustomData();
}, [currentUser]);

/**
* Trigger the user event listener by removing the user from the app.
*/
const deleteUser = useCallback(() => {
// TODO: Update to use only `deleteUser`.
// We currently call both `deleteUser` (deletes from server and client) and
// `removeUser` (deletes from client) due to a bug in `deleteUser` where the
// `currentUser` is not updated to `null`.
app.deleteUser(currentUser);
app.removeUser(currentUser);
}, [app, currentUser]);

useEffect(() => {
/**
* The user listener - Will be invoked on various user related events including
Expand Down Expand Up @@ -196,5 +209,6 @@ export function useDemoSyncTriggers() {
triggerSyncError,
triggerClientReset,
refreshAccessToken,
deleteUser,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import React from 'react';
import {Alert, FlatList, StyleSheet, Text, View} from 'react-native';
import {useAuth, useApp, useUser} from '@realm/react';
import {useAuth} from '@realm/react';

import {Button} from '../components/Button';
import {KioskItem} from '../components/KioskItem';
Expand All @@ -41,11 +41,9 @@ export function StoreScreen() {
triggerSyncError,
triggerClientReset,
refreshAccessToken,
deleteUser,
} = useDemoSyncTriggers();
const {logOut} = useAuth();
const user = useUser();
const app = useApp();


return (
<View style={styles.container}>
Expand Down Expand Up @@ -115,10 +113,7 @@ export function StoreScreen() {
/>
<Button
extraStyles={[styles.button]}
onPress={() => {
app.deleteUser(user);
app.removeUser(user);
}}
onPress={deleteUser}
text="Delete User"
/>
</View>
Expand Down
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f07e03

Please sign in to comment.