-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathmanage.js
151 lines (130 loc) · 3.78 KB
/
manage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// These samples are intended for Web so this import would normally be
// done in HTML however using modules here is more convenient for
// ensuring sample correctness offline.
import firebase from "firebase/app";
import "firebase/auth";
function getUserProfile() {
// [START auth_get_user_profile]
const user = firebase.auth().currentUser;
if (user !== null) {
// The user object has basic properties such as display name, email, etc.
const displayName = user.displayName;
const email = user.email;
const photoURL = user.photoURL;
const emailVerified = user.emailVerified;
// The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getIdToken() instead.
const uid = user.uid;
}
// [END auth_get_user_profile]
}
function getUserProfileProvider() {
// [START auth_get_user_profile_provider]
const user = firebase.auth().currentUser;
if (user !== null) {
user.providerData.forEach((profile) => {
console.log("Sign-in provider: " + profile.providerId);
console.log(" Provider-specific UID: " + profile.uid);
console.log(" Name: " + profile.displayName);
console.log(" Email: " + profile.email);
console.log(" Photo URL: " + profile.photoURL);
});
}
// [END auth_get_user_profile_provider]
}
function updateUserProfile() {
// [START auth_update_user_profile]
const user = firebase.auth().currentUser;
user.updateProfile({
displayName: "Jane Q. User",
photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(() => {
// Update successful
// ...
}).catch((error) => {
// An error occurred
// ...
});
// [END auth_update_user_profile]
}
function updateUserEmail() {
// [START auth_update_user_email]
const user = firebase.auth().currentUser;
user.updateEmail("[email protected]").then(() => {
// Update successful
// ...
}).catch((error) => {
// An error occurred
// ...
});
// [END auth_update_user_email]
}
function sendEmailVerification() {
// [START send_email_verification]
const user = firebase.auth().currentUser;
user.sendEmailVerification().then(() => {
// Email sent.
}).catch((error) => {
// An error ocurred
// ...
});
// [END send_email_verification]
}
function updatePassword() {
function getASecureRandomPassword() {
return "correcthorsebatterystaple";
}
// [START auth_update_password]
const user = firebase.auth().currentUser;
const newPassword = getASecureRandomPassword();
user.updatePassword(newPassword).then(() => {
// Update successful.
}).catch((error) => {
// An error ocurred
// ...
});
// [END auth_update_password]
}
function sendPasswordReset() {
// [START auth_send_password_reset]
const auth = firebase.auth();
const emailAddress = "[email protected]";
auth.sendPasswordResetEmail(emailAddress).then(() => {
// Email sent.
}).catch((error) => {
// An error ocurred
// ...
});
// [END auth_send_password_reset]
}
function deleteUser() {
// [START auth_delete_user]
const user = firebase.auth().currentUser;
user.delete().then(() => {
// User deleted.
}).catch((error) => {
// An error ocurred
// ...
});
// [END auth_delete_user]
}
function reauthenticateWithCredential() {
/**
* @returns {object}
*/
function promptForCredentials() {
return {};
}
// [START auth_reauth_with_credential]
const user = firebase.auth().currentUser;
// TODO(you): prompt the user to re-provide their sign-in credentials
const credential = promptForCredentials();
user.reauthenticateWithCredential(credential).then(() => {
// User re-authenticated.
}).catch((error) => {
// An error occurred
// ...
});
// [END auth_reauth_with_credential]
}