@@ -36,6 +36,38 @@ function getProviders() {
36
36
// [END auth_get_providers]
37
37
}
38
38
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
+
39
71
function linkWithPopup ( ) {
40
72
var provider = new firebase . auth . GoogleAuthProvider ( ) ;
41
73
@@ -76,17 +108,6 @@ function linkWithRedirect() {
76
108
// [END auth_get_redirect_result]
77
109
}
78
110
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
-
90
111
function mergeAccounts ( ) {
91
112
// This is just a dummy variable for sample purposes, the other
92
113
// snippets demonstrate how to get a real credential.
@@ -134,3 +155,25 @@ function mergeAccounts() {
134
155
// [END auth_merge_accounts]
135
156
}
136
157
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