Add user displayname
How do I add a DisplayName
in FireStore? I have read firebase no displayname for user and firebase user photourl and displayname and this but none of them work, since they all refer to Firebase and not Firestore.
firebase google-cloud-firestore
add a comment |
How do I add a DisplayName
in FireStore? I have read firebase no displayname for user and firebase user photourl and displayname and this but none of them work, since they all refer to Firebase and not Firestore.
firebase google-cloud-firestore
add a comment |
How do I add a DisplayName
in FireStore? I have read firebase no displayname for user and firebase user photourl and displayname and this but none of them work, since they all refer to Firebase and not Firestore.
firebase google-cloud-firestore
How do I add a DisplayName
in FireStore? I have read firebase no displayname for user and firebase user photourl and displayname and this but none of them work, since they all refer to Firebase and not Firestore.
firebase google-cloud-firestore
firebase google-cloud-firestore
edited Jan 2 at 14:53
Ishaan Javali
1,3603820
1,3603820
asked Jan 2 at 5:02
Hasan A YousefHasan A Yousef
5,92943969
5,92943969
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can create a cloud function that triggers on account creation as such
functions.auth.user().onCreate(event => {
const firebaseUser = event.data;
return firebase.firestore().collection("users").doc(firebaseUser.uid).set({
name: firebaseUser.displayName || "n/a"
});
});
That will create a document for the user in a collection called users, identified by its UID. Beware that the displayName
is not necessarily set in the auth user object. So you might want to set a default placeholder that you can query for later and ask the user to provide information for.
add a comment |
var config = {
apiKey: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
authDomain: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
databaseURL: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
projectId: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
storageBucket: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
messagingSenderId: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL"
};
firebase.initializeApp(config);
// Initialize Cloud Firestore through Firebase
var firestore = firebase.firestore();
const settings = {/* your settings... */ timestampsInSnapshots: true};
firestore.settings(settings);
firebase.auth().onAuthStateChanged(function(user) {
//check if user is signed in
if (user) {
//user is signed in
//get user display
if (user.displayName !== undefined) {
var username = user.displayName;
//add displayName to firestore
firestore
.collection("users")
.doc(user.uid)
.set({
username: username
}, {merge: true})
.then(function() {
alert('displayName added!');
})
.catch(function(e) {
//there was an error writing to firestore
//check console
console.log(e);
});
} else {
//user has not set displayName
alert('no displayName');
}
}
});
Appreciate your contribution and welcome stakoverflow, but I'm asking aboutfirestore
notfirebase
– Hasan A Yousef
Jan 2 at 17:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001429%2fadd-user-displayname%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can create a cloud function that triggers on account creation as such
functions.auth.user().onCreate(event => {
const firebaseUser = event.data;
return firebase.firestore().collection("users").doc(firebaseUser.uid).set({
name: firebaseUser.displayName || "n/a"
});
});
That will create a document for the user in a collection called users, identified by its UID. Beware that the displayName
is not necessarily set in the auth user object. So you might want to set a default placeholder that you can query for later and ask the user to provide information for.
add a comment |
You can create a cloud function that triggers on account creation as such
functions.auth.user().onCreate(event => {
const firebaseUser = event.data;
return firebase.firestore().collection("users").doc(firebaseUser.uid).set({
name: firebaseUser.displayName || "n/a"
});
});
That will create a document for the user in a collection called users, identified by its UID. Beware that the displayName
is not necessarily set in the auth user object. So you might want to set a default placeholder that you can query for later and ask the user to provide information for.
add a comment |
You can create a cloud function that triggers on account creation as such
functions.auth.user().onCreate(event => {
const firebaseUser = event.data;
return firebase.firestore().collection("users").doc(firebaseUser.uid).set({
name: firebaseUser.displayName || "n/a"
});
});
That will create a document for the user in a collection called users, identified by its UID. Beware that the displayName
is not necessarily set in the auth user object. So you might want to set a default placeholder that you can query for later and ask the user to provide information for.
You can create a cloud function that triggers on account creation as such
functions.auth.user().onCreate(event => {
const firebaseUser = event.data;
return firebase.firestore().collection("users").doc(firebaseUser.uid).set({
name: firebaseUser.displayName || "n/a"
});
});
That will create a document for the user in a collection called users, identified by its UID. Beware that the displayName
is not necessarily set in the auth user object. So you might want to set a default placeholder that you can query for later and ask the user to provide information for.
answered Jan 2 at 5:26
Dennis AlundDennis Alund
646217
646217
add a comment |
add a comment |
var config = {
apiKey: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
authDomain: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
databaseURL: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
projectId: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
storageBucket: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
messagingSenderId: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL"
};
firebase.initializeApp(config);
// Initialize Cloud Firestore through Firebase
var firestore = firebase.firestore();
const settings = {/* your settings... */ timestampsInSnapshots: true};
firestore.settings(settings);
firebase.auth().onAuthStateChanged(function(user) {
//check if user is signed in
if (user) {
//user is signed in
//get user display
if (user.displayName !== undefined) {
var username = user.displayName;
//add displayName to firestore
firestore
.collection("users")
.doc(user.uid)
.set({
username: username
}, {merge: true})
.then(function() {
alert('displayName added!');
})
.catch(function(e) {
//there was an error writing to firestore
//check console
console.log(e);
});
} else {
//user has not set displayName
alert('no displayName');
}
}
});
Appreciate your contribution and welcome stakoverflow, but I'm asking aboutfirestore
notfirebase
– Hasan A Yousef
Jan 2 at 17:26
add a comment |
var config = {
apiKey: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
authDomain: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
databaseURL: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
projectId: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
storageBucket: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
messagingSenderId: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL"
};
firebase.initializeApp(config);
// Initialize Cloud Firestore through Firebase
var firestore = firebase.firestore();
const settings = {/* your settings... */ timestampsInSnapshots: true};
firestore.settings(settings);
firebase.auth().onAuthStateChanged(function(user) {
//check if user is signed in
if (user) {
//user is signed in
//get user display
if (user.displayName !== undefined) {
var username = user.displayName;
//add displayName to firestore
firestore
.collection("users")
.doc(user.uid)
.set({
username: username
}, {merge: true})
.then(function() {
alert('displayName added!');
})
.catch(function(e) {
//there was an error writing to firestore
//check console
console.log(e);
});
} else {
//user has not set displayName
alert('no displayName');
}
}
});
Appreciate your contribution and welcome stakoverflow, but I'm asking aboutfirestore
notfirebase
– Hasan A Yousef
Jan 2 at 17:26
add a comment |
var config = {
apiKey: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
authDomain: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
databaseURL: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
projectId: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
storageBucket: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
messagingSenderId: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL"
};
firebase.initializeApp(config);
// Initialize Cloud Firestore through Firebase
var firestore = firebase.firestore();
const settings = {/* your settings... */ timestampsInSnapshots: true};
firestore.settings(settings);
firebase.auth().onAuthStateChanged(function(user) {
//check if user is signed in
if (user) {
//user is signed in
//get user display
if (user.displayName !== undefined) {
var username = user.displayName;
//add displayName to firestore
firestore
.collection("users")
.doc(user.uid)
.set({
username: username
}, {merge: true})
.then(function() {
alert('displayName added!');
})
.catch(function(e) {
//there was an error writing to firestore
//check console
console.log(e);
});
} else {
//user has not set displayName
alert('no displayName');
}
}
});
var config = {
apiKey: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
authDomain: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
databaseURL: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
projectId: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
storageBucket: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL",
messagingSenderId: "REPLACE_WITH_YOUR_FIREBASE_PROJECT_CREDENTIAL"
};
firebase.initializeApp(config);
// Initialize Cloud Firestore through Firebase
var firestore = firebase.firestore();
const settings = {/* your settings... */ timestampsInSnapshots: true};
firestore.settings(settings);
firebase.auth().onAuthStateChanged(function(user) {
//check if user is signed in
if (user) {
//user is signed in
//get user display
if (user.displayName !== undefined) {
var username = user.displayName;
//add displayName to firestore
firestore
.collection("users")
.doc(user.uid)
.set({
username: username
}, {merge: true})
.then(function() {
alert('displayName added!');
})
.catch(function(e) {
//there was an error writing to firestore
//check console
console.log(e);
});
} else {
//user has not set displayName
alert('no displayName');
}
}
});
answered Jan 2 at 13:19
Mwila KaundaMwila Kaunda
11
11
Appreciate your contribution and welcome stakoverflow, but I'm asking aboutfirestore
notfirebase
– Hasan A Yousef
Jan 2 at 17:26
add a comment |
Appreciate your contribution and welcome stakoverflow, but I'm asking aboutfirestore
notfirebase
– Hasan A Yousef
Jan 2 at 17:26
Appreciate your contribution and welcome stakoverflow, but I'm asking about
firestore
not firebase
– Hasan A Yousef
Jan 2 at 17:26
Appreciate your contribution and welcome stakoverflow, but I'm asking about
firestore
not firebase
– Hasan A Yousef
Jan 2 at 17:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001429%2fadd-user-displayname%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown