Skip to content

Commit

Permalink
Merge 14490d2 into d6cfba8
Browse files Browse the repository at this point in the history
  • Loading branch information
takameyer committed Oct 23, 2023
2 parents d6cfba8 + 14490d2 commit 4a048a1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"enabled": false
"enabled": true,
"mongo_service_name": "mongodb-atlas",
"database_name": "AuthExample",
"collection_name": "Users",
"user_id_field": "user_id",
"on_user_creation_function_name": "onUserCreation"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
"private": false,
"run_as_system": true,
"disable_arg_logs": true
},
{
"name": "onUserCreation",
"private": false,
"run_as_system": true,
"disable_arg_logs": true
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable */

/**
* Adds custom user data to the Users collection when a new user is created.
*/
exports = async function onUserCreation(user) {
const customUserDataCollection = context.services.get("mongodb-atlas").db("AuthExample").collection("Users");
try {
await customUserDataCollection.insertOne({
// Save the user's account ID to your configured user_id_field
user_id: user.id,
// Store any other user data you want
team: "service",
});
} catch (e) {
console.error(`Failed to create custom user data document for user:${user.id}`);
throw e;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export function StoreScreen() {
const user = useUser();
const app = useApp();


return (
<View style={styles.container}>
<View style={styles.header}>
Expand Down Expand Up @@ -83,6 +82,11 @@ 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]}
Expand Down Expand Up @@ -121,6 +125,13 @@ export function StoreScreen() {
}}
text="Delete User"
/>
<Button
extraStyles={[styles.button]}
onPress={() => {
user.refreshCustomData();
}}
text="Refresh User Data"
/>
</View>
</View>
</>
Expand Down

0 comments on commit 4a048a1

Please sign in to comment.