Skip to content

Commit cee9068

Browse files
committed
Finish linking snippets
1 parent f5966cd commit cee9068

File tree

1 file changed

+54
-11
lines changed

1 file changed

+54
-11
lines changed

auth/link-multiple-accounts.js

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,38 @@ function getProviders() {
3636
// [END auth_get_providers]
3737
}
3838

39+
function simpleLink() {
40+
// This is just a dummy variable for sample purposes, the other
41+
// snippets demonstrate how to get a real credential.
42+
var credential = new firebase.auth.AuthCredential();
43+
44+
// [START auth_simple_link]
45+
auth.currentUser.linkWithCredential(credential)
46+
.then(function(usercred) {
47+
var user = usercred.user;
48+
console.log("Account linking success", user);
49+
}).catch(function(error) {
50+
console.log("Account linking error", error);
51+
});
52+
// [END auth_simple_link]
53+
}
54+
55+
function anonymousLink() {
56+
// This is just a dummy variable for sample purposes, the other
57+
// snippets demonstrate how to get a real credential.
58+
var credential = new firebase.auth.AuthCredential();
59+
60+
// [START auth_anonymous_link]
61+
auth.currentUser.linkWithCredential(credential)
62+
.then(function(usercred) {
63+
var user = usercred.user;
64+
console.log("Anonymous account successfully upgraded", user);
65+
}).catch(function(error) {
66+
console.log("Error upgrading anonymous account", error);
67+
});
68+
// [END auth_anonymous_link]
69+
}
70+
3971
function linkWithPopup() {
4072
var provider = new firebase.auth.GoogleAuthProvider();
4173

@@ -76,17 +108,6 @@ function linkWithRedirect() {
76108
// [END auth_get_redirect_result]
77109
}
78110

79-
// For one, the user variable in the line:
80-
// return user.delete().then(function() {
81-
// does not have a .delete function, it would need to be user.user.delete()
82-
// & in this example they suggest:
83-
// // Merge prevUser and currentUser data stored in Firebase
84-
// which in this auth context (& assuming basic security rules enabled) would mean you would only have access to currentUser ’s storage,
85-
// but then they delete the current user & link the credential to the previous user. In otherwords you would only be able to merge the previous user’s
86-
// data into the current user’s storage, however the current user is deleted & no longer accessible
87-
// So I’d just like a sanity check here that this example is indeed a flawed approach!
88-
89-
90111
function mergeAccounts() {
91112
// This is just a dummy variable for sample purposes, the other
92113
// snippets demonstrate how to get a real credential.
@@ -134,3 +155,25 @@ function mergeAccounts() {
134155
// [END auth_merge_accounts]
135156
}
136157

158+
function makeEmailCredential() {
159+
var email = "test@test.com";
160+
var password = "abcde12345";
161+
162+
// [START auth_make_email_credential]
163+
var credential = firebase.auth.EmailAuthProvider.credential(email, password);
164+
// [END auth_make_email_credential]
165+
}
166+
167+
function unlink() {
168+
var user = auth.currentUser;
169+
170+
// [START auth_unlink_provider]
171+
user.unlink(providerId).then(function() {
172+
// Auth provider unlinked from account
173+
// ...
174+
}).catch(function(error) {
175+
// An error happened
176+
// ...
177+
});
178+
// [END auth_unlink_provider]
179+
}

0 commit comments

Comments
 (0)