Skip to content

Commit c018b09

Browse files
authored
Merge pull request #2 from srijak/ios-customToken-support
added support for signInWithCustomToken on ios.
2 parents 155b219 + 0e328fc commit c018b09

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ server.signInWithEmail('[email protected]', '123456')
166166
})
167167
```
168168

169+
#### signInWithCustomToken()
170+
171+
To sign a user using a self-signed custom token, use the `signInWithCustomToken()` function. It accepts one parameter, the custom token:
172+
173+
```javascript
174+
server.signInWithCustomToken(TOKEN)
175+
.then((user) => {
176+
console.log('User successfully logged in', user)
177+
})
178+
.catch((err) => {
179+
console.error('User signin error', err);
180+
})
181+
```
182+
169183
#### signInWithProvider()
170184

171185
We can use an external authentication provider, such as twitter/facebook for authentication. In order to use an external provider, we need to include another library to handle authentication.

firestack.ios.js

+9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ export default class Firestack {
8080
return promisify('signInWithProvider')(provider, authToken, authSecret);
8181
}
8282

83+
/**
84+
* Sign the user in with a custom auth token
85+
* @param {string} customToken A self-signed custom auth token.
86+
* @return {Promise} A promise resolved upon completion
87+
*/
88+
signInWithCustomToken(customToken) {
89+
return promisify('signInWithCustomToken')(customToken);
90+
}
91+
8392
/**
8493
* Reauthenticate a user with a third-party authentication provider
8594
* @param {string} provider The provider name

ios/Firestack/Firestack.m

+21
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ @implementation Firestack
2828
}
2929
}
3030

31+
RCT_EXPORT_METHOD(signInWithCustomToken:
32+
(NSString *)customToken
33+
callback:(RCTResponseSenderBlock) callback)
34+
{
35+
[[FIRAuth auth]
36+
signInWithCustomToken:customToken
37+
completion:^(FIRUser *user, NSError *error) {
38+
39+
if (user != nil) {
40+
NSDictionary *userProps = [self userPropsFromFIRUser:user];
41+
callback(@[[NSNull null], userProps]);
42+
} else {
43+
NSDictionary *err =
44+
[self handleFirebaseError:@"signinError"
45+
error:error
46+
withUser:user];
47+
callback(@[err]);
48+
}
49+
}];
50+
}
51+
3152
RCT_EXPORT_METHOD(signInWithProvider:
3253
(NSString *)provider
3354
token:(NSString *)authToken

0 commit comments

Comments
 (0)