-
Notifications
You must be signed in to change notification settings - Fork 586
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
Additions to custom user data #6221
Merged
takameyer
merged 8 commits into
andrew/custom-user-data-example
from
lj/custom-user-data-additions
Oct 31, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6a63c90
Move 'deleteUser' responsibility to 'useDemoSyncTriggers'.
elle-j 89d05a2
Type the user data.
elle-j a47ae29
Move user data text above connection text.
elle-j c96d566
Remove 'rollup-plugin-dts' from package lock.
elle-j ac95bc0
Change 'onUserCreation' to run as 'App Auth' instead of 'System User'.
elle-j b52880e
Add permission role to custom data collection.
elle-j d91c4d5
Update README.
elle-j 53afe75
Update custom user data rules.json formatting.
elle-j File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...s/rn-connection-and-error/backend/data_sources/mongodb-atlas/AuthExample/Users/rules.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"collection": "Users", | ||
"database": "AuthExample", | ||
"roles": [ | ||
{ | ||
"name": "ThisUser", | ||
"apply_when": { | ||
"user_id": "%%user.id%%" | ||
}, | ||
"document_filters": { | ||
"write": {}, | ||
"read": {} | ||
}, | ||
"read": true, | ||
"write": true, | ||
"insert": false, | ||
"delete": false, | ||
"search": false | ||
} | ||
], | ||
"filters": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
{ | ||
"name": "onUserCreation", | ||
"private": false, | ||
"run_as_system": true, | ||
"disable_arg_logs": true | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, useUser} from '@realm/react'; | ||
|
||
import {Button} from '../components/Button'; | ||
import {KioskItem} from '../components/KioskItem'; | ||
|
@@ -27,6 +27,18 @@ import {fonts} from '../styles/fonts'; | |
import {useDemoSyncTriggers} from '../hooks/useDemoSyncTriggers'; | ||
import {useStore} from '../providers/StoreProvider'; | ||
|
||
/** | ||
* The properties used as custom user data. | ||
* | ||
* @note | ||
* Our backend function `onUserCreation()` adds these fields | ||
* when the user registers. | ||
*/ | ||
type CustomUserData = { | ||
user_id: string; | ||
team: string; | ||
}; | ||
|
||
/** | ||
* Screen for showing the kiosks and products in the store, | ||
* as well as buttons for triggering various listeners. | ||
|
@@ -41,10 +53,10 @@ export function StoreScreen() { | |
triggerSyncError, | ||
triggerClientReset, | ||
refreshAccessToken, | ||
deleteUser, | ||
} = useDemoSyncTriggers(); | ||
const {logOut} = useAuth(); | ||
const user = useUser(); | ||
const app = useApp(); | ||
const user = useUser<{}, CustomUserData, {}>(); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
|
@@ -72,6 +84,11 @@ export function StoreScreen() { | |
/> | ||
</View> | ||
<View style={styles.triggers}> | ||
<View style={styles.status}> | ||
<Text style={styles.statusText}> | ||
Team: {user.customData.team} | ||
</Text> | ||
</View> | ||
Comment on lines
+87
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Just moved this above the "Connected" text. But also, removed the |
||
<View style={styles.status}> | ||
<Text style={styles.statusText}> | ||
Status: {isConnected ? 'Connected 🟢' : 'Not connected 🔴'} | ||
|
@@ -82,11 +99,6 @@ export function StoreScreen() { | |
text={isConnected ? 'Disconnect' : 'Connect'} | ||
/> | ||
</View> | ||
<View style={styles.status}> | ||
<Text style={styles.statusText}> | ||
Team: {user.customData?.team || '-'} | ||
</Text> | ||
</View> | ||
<View style={styles.triggerButtons}> | ||
<Button | ||
extraStyles={[styles.button]} | ||
|
@@ -119,10 +131,7 @@ export function StoreScreen() { | |
/> | ||
<Button | ||
extraStyles={[styles.button]} | ||
onPress={() => { | ||
app.deleteUser(user); | ||
app.removeUser(user); | ||
}} | ||
onPress={deleteUser} | ||
text="Delete User" | ||
/> | ||
<Button | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes here and some in
StoreScreen.tsx
(i.e. moving the responsibility of deleting the user to this file) are the same as in the previous PR. But since this one will be merged after, the previous changes probably would have been overwritten had it not been changed here as well.