Skip to content

Commit d01b676

Browse files
Willham12mikehardy
authored andcommitted
feat(auth)!: use native isSignInWithEmailLink - returns Promise<boolean> vs boolean
- style(auth, ios): result of `yarn lint:ios:fix` - test(auth): await isSignInWithEmailLink, note apiKey platform difference BREAKING CHANGE: return type of auth isSignInWithEmailLink changed from boolean to Promise<boolean>
1 parent c0c5054 commit d01b676

File tree

8 files changed

+55
-15
lines changed

8 files changed

+55
-15
lines changed

Diff for: packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java

+14
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,20 @@ private void createUserWithEmailAndPassword(
402402
});
403403
}
404404

405+
/**
406+
* isSignInWithEmailLink
407+
*
408+
* @param email
409+
* @param promise
410+
*/
411+
@ReactMethod
412+
public void isSignInWithEmailLink(String appName, String emailLink, final Promise promise) {
413+
Log.d(TAG, "isSignInWithEmailLink");
414+
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
415+
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
416+
promise.resolve(firebaseAuth.isSignInWithEmailLink(emailLink));
417+
}
418+
405419
/**
406420
* signInWithEmailAndPassword
407421
*

Diff for: packages/auth/e2e/emailLink.e2e.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,18 @@ describe('auth() -> emailLink Provider', function () {
8181
const emailLink3 = 'https://www.example.com/action?mode=signIn';
8282
const emailLink4 =
8383
'https://x59dg.app.goo.gl/?link=https://rnfirebase-b9ad4.firebaseapp.com/__/auth/action?apiKey%3Dfoo%26mode%3DsignIn%26oobCode%3Dbar';
84-
85-
should.equal(true, isSignInWithEmailLink(auth, emailLink1));
86-
should.equal(false, isSignInWithEmailLink(auth, emailLink2));
87-
should.equal(false, isSignInWithEmailLink(auth, emailLink3));
88-
should.equal(true, isSignInWithEmailLink(auth, emailLink4));
84+
const emailLink5 = 'https://www.example.com/action?mode=signIn&oobCode=oobCode&apiKey=foo';
85+
86+
// ios does not require apiKey, but android and web/other do
87+
if (!Platform.ios) {
88+
should.equal(false, await isSignInWithEmailLink(auth, emailLink1));
89+
} else {
90+
should.equal(true, await isSignInWithEmailLink(auth, emailLink1));
91+
}
92+
should.equal(false, await isSignInWithEmailLink(auth, emailLink2));
93+
should.equal(false, await isSignInWithEmailLink(auth, emailLink3));
94+
should.equal(true, await isSignInWithEmailLink(auth, emailLink4));
95+
should.equal(true, await isSignInWithEmailLink(auth, emailLink5));
8996
});
9097
});
9198

Diff for: packages/auth/ios/RNFBAuth/RNFBAuthModule.m

+9
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ - (void)invalidate {
254254
}];
255255
}
256256

257+
RCT_EXPORT_METHOD(isSignInWithEmailLink
258+
: (FIRApp *)firebaseApp
259+
: (NSString *)emailLink
260+
: (RCTPromiseResolveBlock)resolve
261+
: (RCTPromiseRejectBlock)reject) {
262+
resolve(
263+
@([RCTConvert BOOL:@([[FIRAuth authWithApp:firebaseApp] isSignInWithEmailLink:emailLink])]));
264+
}
265+
257266
RCT_EXPORT_METHOD(signInWithEmailLink
258267
: (FIRApp *)firebaseApp
259268
: (NSString *)email

Diff for: packages/auth/lib/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2013,12 +2013,12 @@ export namespace FirebaseAuthTypes {
20132013
* #### Example
20142014
*
20152015
* ```js
2016-
* const signedInWithLink = firebase.auth().isSignInWithEmailLink(link);
2016+
* const signedInWithLink = await firebase.auth().isSignInWithEmailLink(link);
20172017
* ```
20182018
*
20192019
* @param emailLink The email link to check whether the user signed in with it.
20202020
*/
2021-
isSignInWithEmailLink(emailLink: string): boolean;
2021+
isSignInWithEmailLink(emailLink: string): Promise<boolean>;
20222022

20232023
/**
20242024
* Signs the user in with an email link.

Diff for: packages/auth/lib/index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,7 @@ class FirebaseAuthModule extends FirebaseModule {
361361
}
362362

363363
isSignInWithEmailLink(emailLink) {
364-
return (
365-
typeof emailLink === 'string' &&
366-
(emailLink.includes('mode=signIn') || emailLink.includes('mode%3DsignIn')) &&
367-
(emailLink.includes('oobCode=') || emailLink.includes('oobCode%3D'))
368-
);
364+
return this.native.isSignInWithEmailLink(emailLink);
369365
}
370366

371367
signInWithEmailLink(email, emailLink) {

Diff for: packages/auth/lib/modular/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ export function initializeRecaptchaConfig(auth: Auth): Promise<void>;
169169
*
170170
* @param auth - The Auth instance.
171171
* @param emailLink - The email link to check.
172-
* @returns True if the link is a sign-in with email link.
172+
* @returns A promise that resolves if the link is a sign-in with email link.
173173
*/
174-
export function isSignInWithEmailLink(auth: Auth, emailLink: string): boolean;
174+
export function isSignInWithEmailLink(auth: Auth, emailLink: string): Promise<boolean>;
175175

176176
/**
177177
* Adds an observer for changes to the user's sign-in state.

Diff for: packages/auth/lib/modular/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export async function getRedirectResult(auth, resolver) {
165165
* Checks if an incoming link is a sign-in with email link suitable for signInWithEmailLink().
166166
* @param {Auth} auth - The Auth instance.
167167
* @param {string} emailLink - The email link to check.
168-
* @returns {boolean}
168+
* @returns {Promise<boolean>}
169169
*/
170170
export function isSignInWithEmailLink(auth, emailLink) {
171171
return auth.isSignInWithEmailLink(emailLink);

Diff for: packages/auth/lib/web/RNFBAuthModule.js

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
multiFactor,
1111
createUserWithEmailAndPassword,
1212
signInWithEmailAndPassword,
13+
isSignInWithEmailLink,
1314
signInWithEmailLink,
1415
signInWithCustomToken,
1516
sendPasswordResetEmail,
@@ -449,6 +450,19 @@ export default {
449450
});
450451
},
451452

453+
/**
454+
* Check if a sign in with email link is valid
455+
* @param {string} appName - The name of the app to get the auth instance for.
456+
* @param {string} emailLink - The email link to sign in with.
457+
* @returns {Promise<boolean>} - Whether the link is a valid sign in with email link.
458+
*/
459+
async isSignInWithEmailLink(appName, emailLink) {
460+
return guard(async () => {
461+
const auth = getCachedAuthInstance(appName);
462+
return await isSignInWithEmailLink(auth, emailLink);
463+
});
464+
},
465+
452466
/**
453467
* Sign in with email link.
454468
* @param {string} appName - The name of the app to get the auth instance for.

0 commit comments

Comments
 (0)