Skip to content

Commit

Permalink
feat(auth): Expose modular API that matches the Firebase web JS SDK v…
Browse files Browse the repository at this point in the history
…9 API
  • Loading branch information
Lyokone authored and mikehardy committed Sep 18, 2023
1 parent acc58da commit 56381a1
Show file tree
Hide file tree
Showing 12 changed files with 6,543 additions and 2,409 deletions.
2,789 changes: 1,968 additions & 821 deletions packages/auth/e2e/auth.e2e.js

Large diffs are not rendered by default.

39 changes: 27 additions & 12 deletions packages/auth/e2e/emailLink.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ const { getLastOob, signInUser } = require('./helpers');

describe('auth() -> emailLink Provider', function () {
beforeEach(async function () {
if (firebase.auth().currentUser) {
await firebase.auth().signOut();
const { getAuth, signOut } = authModular;

const auth = getAuth();
if (auth.currentUser) {
await signOut(auth);
await Utils.sleep(50);
}
});

describe('sendSignInLinkToEmail', function () {
it('should send email', async function () {
const { getAuth, sendSignInLinkToEmail } = authModular;

const auth = getAuth();
const random = Utils.randString(12, '#aA');
const email = `${random}@${random}.com`;
// const email = 'MANUAL TEST EMAIL HERE';
const actionCodeSettings = {
url: 'http://localhost:1337/authLinkFoo?bar=1234',
handleCodeInApp: true,
Expand All @@ -25,10 +30,13 @@ describe('auth() -> emailLink Provider', function () {
minimumVersion: '12',
},
};
await firebase.auth().sendSignInLinkToEmail(email, actionCodeSettings);
await sendSignInLinkToEmail(auth, email, actionCodeSettings);
});

it('sign in via email works', async function () {
const { getAuth, sendSignInLinkToEmail } = authModular;

const auth = getAuth();
const random = Utils.randString(12, '#aa');
const email = `${random}@${random}.com`;
const continueUrl = 'http://localhost:1337/authLinkFoo?bar=' + random;
Expand All @@ -44,7 +52,7 @@ describe('auth() -> emailLink Provider', function () {
minimumVersion: '12',
},
};
await firebase.auth().sendSignInLinkToEmail(email, actionCodeSettings);
await sendSignInLinkToEmail(auth, email, actionCodeSettings);
const oobInfo = await getLastOob(email);
oobInfo.oobLink.should.containEql(encodeURIComponent(continueUrl));
const signInResponse = await signInUser(oobInfo.oobLink);
Expand All @@ -53,39 +61,46 @@ describe('auth() -> emailLink Provider', function () {
});

xit('should send email with defaults', async function () {
const { getAuth, sendSignInLinkToEmail } = authModular;

const auth = getAuth();
const random = Utils.randString(12, '#aA');
const email = `${random}@${random}.com`;

await firebase.auth().sendSignInLinkToEmail(email);
await sendSignInLinkToEmail(auth, email);
});
});

describe('isSignInWithEmailLink', function () {
it('should return true/false', async function () {
const { getAuth, isSignInWithEmailLink } = authModular;

const auth = getAuth();
const emailLink1 = 'https://www.example.com/action?mode=signIn&oobCode=oobCode';
const emailLink2 = 'https://www.example.com/action?mode=verifyEmail&oobCode=oobCode';
const emailLink3 = 'https://www.example.com/action?mode=signIn';
const emailLink4 =
'https://x59dg.app.goo.gl/?link=https://rnfirebase-b9ad4.firebaseapp.com/__/auth/action?apiKey%3Dfoo%26mode%3DsignIn%26oobCode%3Dbar';

should.equal(true, firebase.auth().isSignInWithEmailLink(emailLink1));
should.equal(false, firebase.auth().isSignInWithEmailLink(emailLink2));
should.equal(false, firebase.auth().isSignInWithEmailLink(emailLink3));
should.equal(true, firebase.auth().isSignInWithEmailLink(emailLink4));
should.equal(true, isSignInWithEmailLink(auth, emailLink1));
should.equal(false, isSignInWithEmailLink(auth, emailLink2));
should.equal(false, isSignInWithEmailLink(auth, emailLink3));
should.equal(true, isSignInWithEmailLink(auth, emailLink4));
});
});

// FOR MANUAL TESTING ONLY
xdescribe('signInWithEmailLink', function () {
it('should signIn', async function () {
const auth = getAuth();
const email = 'MANUAL TEST EMAIL HERE';
const emailLink = 'MANUAL TEST CODE HERE';

const userCredential = await firebase.auth().signInWithEmailLink(email, emailLink);
const userCredential = await signInWithEmailLink(auth, email, emailLink);

userCredential.user.email.should.equal(email);

await await firebase.auth().signOut();
await signOut(auth);
});
});
});
Loading

0 comments on commit 56381a1

Please sign in to comment.