Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add updates to the addition of deleteUser in example app #6208

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this TODO until #5327 is fixed.

// 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.

Loading