-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathauthentication.js
160 lines (140 loc) · 4.73 KB
/
authentication.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
152
153
154
155
156
157
158
159
160
import {NativeModules, NativeEventEmitter} from 'react-native';
const FirestackAuth = NativeModules.FirestackAuth
const FirestackAuthEvt = new NativeEventEmitter(FirestackAuth);
import promisify from '../utils/promisify'
import { Base } from './base'
export class Authentication extends Base {
constructor(firestack, options={}) {
super(firestack, options);
}
// Auth
listenForAuth(callback) {
this.log.info('Setting up listenForAuth callback');
const sub = this._on('listenForAuth', callback, FirestackAuthEvt);
FirestackAuth.listenForAuth();
this.log.info('Listening for auth...');
return promisify(() => sub, FirestackAuth)(sub);
}
unlistenForAuth() {
this.log.info('Unlistening for auth');
this._off('listenForAuth');
return promisify('unlistenForAuth', FirestackAuth)();
}
/**
* Create a user with the email/password functionality
* @param {string} email The user's email
* @param {string} password The user's password
* @return {Promise} A promise indicating the completion
*/
createUserWithEmail(email, password) {
this.log.info('Creating user with email', email);
return promisify('createUserWithEmail', FirestackAuth)(email, password);
}
/**
* Sign a user in with email/password
* @param {string} email The user's email
* @param {string} password The user's password
* @return {Promise} A promise that is resolved upon completion
*/
signInWithEmail(email, password) {
return promisify('signInWithEmail', FirestackAuth)(email, password)
}
/**
* Sign the user in with a third-party authentication provider
* @param {string} provider The name of the provider to use for login
* @param {string} authToken The authToken granted by the provider
* @param {string} authSecret The authToken secret granted by the provider
* @return {Promise} A promise resolved upon completion
*/
signInWithProvider(provider, authToken, authSecret) {
return promisify('signInWithProvider', FirestackAuth)(provider, authToken, authSecret)
}
/**
* Sign the user in with a custom auth token
* @param {string} customToken A self-signed custom auth token.
* @return {Promise} A promise resolved upon completion
*/
signInWithCustomToken(customToken) {
return promisify('signInWithCustomToken', FirestackAuth)(customToken)
}
/**
* Sign a user in anonymously
* @return {Promise} A promise resolved upon completion
*/
signInAnonymously() {
return promisify('signInAnonymously', FirestackAuth)();
}
/**
* Reauthenticate a user with a third-party authentication provider
* @param {string} provider The provider name
* @param {string} token The authToken granted by the provider
* @param {string} secret The authTokenSecret granted by the provider
* @return {Promise} A promise resolved upon completion
*/
reauthenticateWithCredentialForProvider(provider, token, secret) {
return promisify('reauthenticateWithCredentialForProvider', FirestackAuth)(provider, token, secret)
}
/**
* Update the current user's email
* @param {string} email The user's _new_ email
* @return {Promise} A promise resolved upon completion
*/
updateUserEmail(email) {
return promisify('updateUserEmail', FirestackAuth)(email);
}
/**
* Update the current user's password
* @param {string} email the new password
* @return {Promise}
*/
updatePassword(password) {
return promisify('updateUserPassword', FirestackAuth)(password);
}
/**
* Send reset password instructions via email
* @param {string} email The email to send password reset instructions
*/
sendPasswordResetWithEmail(email) {
return promisify('sendPasswordResetWithEmail', FirestackAuth)(email);
}
/**
* Delete the current user
* @return {Promise}
*/
deleteUser() {
return promisify('deleteUser', FirestackAuth)()
}
/**
* get the token of current user
* @return {Promise}
*/
getToken() {
return promisify('getToken', FirestackAuth)()
}
/**
* Update the current user's profile
* @param {Object} obj An object containing the keys listed [here](https://firebase.google.com/docs/auth/ios/manage-users#update_a_users_profile)
* @return {Promise}
*/
updateUserProfile(obj) {
return promisify('updateUserProfile', FirestackAuth)(obj);
}
/**
* Sign the current user out
* @return {Promise}
*/
signOut() {
return promisify('signOut', FirestackAuth)();
}
/**
* Get the currently signed in user
* @return {Promise}
*/
getCurrentUser() {
return promisify('getCurrentUser', FirestackAuth)();
}
get namespace() {
return 'firestack:auth';
}
}
export default Authentication