Authentication

auth.applyActionCode(code)
Generator

Applies a verification code sent to the user by email or other out-of-band mechanism.

Arguments

TypeDescription
code
Optional

String

A verification code sent to the user.

Example

function* applyActionCodeSaga(code) {
  try {
    yield call(rsf.auth.applyActionCode, code);
    yield put(applyActionCodeSuccess());
  }
  catch(error) {
    yield put(applyActionCodeFailure(error));
  }
}

auth.channel()
Function

Gets a redux-saga Channel which emits every user change.

Output

A redux-saga Channel which emits for every user change.

Example

function* syncUserSaga() {
  const channel = yield call(rsf.auth.channel);

  while(true) {
    const { error, user } = yield take(channel);

    if (user) yield put(syncUser(user));
    else yield put(syncError(error));
  }
}

auth.confirmPasswordReset(code, newPassword)
Generator

Completes the password reset process, given a confirmation code and new password.

Arguments

TypeDescription
code
Optional

String

The confirmation code send via email to the user.

newPassword
Optional

String

The new password.

Example

function* confirmPasswordResetSaga(code, newPassword) {
  try {
    yield call(rsf.auth.confirmPasswordReset, code, newPassword);
    yield put(confirmPasswordResetSuccess());
  }
  catch(error) {
    yield put(confirmPasswordResetFailure(error));
  }
}

auth.createUserWithEmailAndPassword(email, password)
Generator

Creates a new user account associated with the specified email address and password.

Arguments

TypeDescription
email
Optional

String

The user's email address.

password
Optional

String

The user's password.

Output

A firebase.User instance.

Example

function* createUserSaga(email, password) {
  try {
    const user = yield call(rsf.auth.createUserWithEmailAndPassword, email, password);
    yield put(createUserSuccess(user));
  }
  catch(error) {
    yield put(createUserFailure(error));
  }
}

auth.deleteProfile()
Generator

Deletes and signs out the user.

Example

function* deleteProfileSaga() {
  try {
    yield call(rsf.auth.deleteProfile);
    yield put(deleteProfileSuccess());
  }
  catch(error) {
    yield put(deleteProfileFailure(error));
  }
}

auth.linkWithPopup(authProvider)
Generator

Links the authenticated provider to the user account using a pop-up based OAuth flow.

Arguments

TypeDescription
authProvider
Optional

A firebase.auth.AuthProvider object.

The authentication provider to use for the request.

Output

A firebase.auth.UserCredential instance.

Example

const authProvider = new firebase.auth.GoogleAuthProvider();

function* linkSaga() {
  try {
    const data = yield call(rsf.auth.linkWithPopup, authProvider);
    yield put(linkSuccess(data));
  } catch(error) {
    yield put(loginFailure(error));
  }
}

auth.linkWithRedirect(authProvider)
Generator

Links the authenticated provider to the user account using a full-page redirect flow.

Arguments

TypeDescription
authProvider
Optional

A firebase.auth.AuthProvider object.

The authentication provider to use for the request.

Example

const authProvider = new firebase.auth.GoogleAuthProvider();

function* linkSaga() {
  try {
    yield call(rsf.auth.linkWithRedirect, authProvider);
  } catch(error) {
    yield put(loginFailure(error));
  }
}

auth.sendEmailVerification(actionCodeSettings)
Generator

Sends a verification email to a user.

Arguments

TypeDescription
actionCodeSettings
Optional

An firebase.auth.ActionCodeSettings

The action code settings.

Example

function* emailVerificationSaga(actionCodeSettings) {
  try {
    yield call(rsf.auth.sendEmailVerification, actionCodeSettings);
    yield put(emailVerificationSendSuccess());
  }
  catch(error) {
    yield put(emailVerificationSendFailure(error));
  }
}

auth.sendPasswordResetEmail(email, actionCodeSettings)
Generator

Sends a password reset email to the given email address.

Arguments

TypeDescription
email
Optional

String

The email address with the password to be reset.

actionCodeSettings
Optional

An firebase.auth.ActionCodeSettings

The action code settings.

Example

function* sendPasswordResetEmailSaga(email, actionCodeSettings) {
  try {
    yield call(rsf.auth.sendPasswordResetEmail, email, actionCodeSettings);
    yield put(sendPasswordResetEmailSuccess());
  }
  catch(error) {
    yield put(sendPasswordResetEmailFailure(error));
  }
}

auth.signInAndRetrieveDataWithCredential(credential)
Generator

Starts the login process with the given credentials and returns any available additional user information, such as user name.

Arguments

TypeDescription
credential
Optional

A firebase.auth.AuthCredential

The authentication credential.

Output

A firebase.auth.UserCredential instance.

Example

function* loginSaga() {
  const credential = yield select(...)
  try {
    const userCredentials = yield call(rsf.auth.signInAndRetrieveDataWithCredential, credential);
    yield put(loginSuccess(userCredentials));
  }
  catch(error) {
    yield put(loginFailure(error));
  }
}

auth.signInAnonymously()
Generator

Starts the login process as an anonymous user.

Output

A firebase.User instance.

Example

function* loginSaga() {
  try {
    const data = yield call(rsf.auth.signInAnonymously, authProvider);
    yield put(loginSuccess(data));
  }
  catch(error) {
    yield put(loginFailure(error));
  }
}

auth.signInWithCredential(credential)
Generator

Starts the login process with the given credentials.

Arguments

TypeDescription
credential
Optional

A firebase.auth.AuthCredential

The authentication credential.

Output

A firebase.User instance.

Example

function* loginSaga() {
  const credential = yield select(...)
  try {
    const user = yield call(rsf.auth.signInWithCredential, credential);
    yield put(loginSuccess(user));
  }
  catch(error) {
    yield put(loginFailure(error));
  }
}

auth.signInWithCustomToken(token)
Generator

Starts the login process using a custom token.

Arguments

TypeDescription
token
Optional

String

The custom token to sign in with.

Output

A firebase.User instance.

Example

function* loginSaga() {
  const token = yield select(...)
  try {
    const user = yield call(rsf.auth.signInWithCustomToken, token);
    yield put(loginSuccess(user));
  }
  catch(error) {
    yield put(loginFailure(error));
  }
}

auth.signInWithEmailAndPassword(email, password)
Generator

Starts the login process using an email address and password.

Arguments

TypeDescription
email
Optional

String

The user's email address.

password
Optional

String

The user's password.

Output

A firebase.User instance.

Example

function* loginSaga(email, password) {
  try {
    const data = yield call(rsf.auth.signInWithEmailAndPassword, email, password);
    yield put(loginSuccess(data));
  }
  catch(error) {
    yield put(loginFailure(error));
  }
}

auth.signInWithPhoneNumber(phoneNumber, applicationVerifier)
Generator

Starts the login process using the specified phone number.

Arguments

TypeDescription
phoneNumber
Optional

String

The user's phone number in E.164 format (e.g. +16505550101).

applicationVerifier
Optional

A firebase.auth.ApplicationVerifier

The verifier to use.

Output

A firebase.auth.ConfirmationResult instance.

Example

const applicationVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');

function* loginSaga() {
  const phoneNumber = yield select(state => ...)

  try {
    const confirmationResult = yield call(rsf.auth.signInWithPhoneNumber, phoneNumber, applicationVerifier);
    const verificationCode = /* implement your own logic to get the user's verification code */
    const credentials = yield call(confirmationResult.confirm, verificationCode);
    yield put(loginSuccess(credentials));
  }
  catch(error) {
    yield put(loginFailure(error));
  }
}

auth.signInWithPopup(authProvider)
Generator

Starts the login process using the specified AuthProvider.

Arguments

TypeDescription
authProvider
Optional

A firebase.auth.AuthProvider object.

The authentication provider to use for the request.

Output

A firebase.auth.AuthCredential instance.

Example

const authProvider = new firebase.auth.GoogleAuthProvider();

function* loginSaga() {
  try {
    const data = yield call(rsf.auth.signInWithPopup, authProvider);
    yield put(loginSuccess(data));
  }
  catch(error) {
    yield put(loginFailure(error));
  }
}

auth.signInWithRedirect(authProvider)
Generator

Starts the login process using the specified AuthProvider.

Arguments

TypeDescription
authProvider
Optional

A firebase.auth.AuthProvider object.

The authentication provider to use for the request.

Example

const authProvider = new firebase.auth.GoogleAuthProvider();

function* loginSaga() {
  try {
    yield call(rsf.auth.signInWithRedirect, authProvider);
    yield put(loginSuccess());
  }
  catch(error) {
    yield put(loginFailure(error));
  }
}

auth.signOut()
Generator

Logs the user out.

Example

function* signOutSaga() {
  try {
    const data = yield call(rsf.auth.signOut);
    yield put(signOutSuccess(data));
  }
  catch(error) {
    yield put(signOutFailure(error));
  }
}

Unlinks a provider from a user account.

Arguments

TypeDescription
authProvider
Optional

A firebase.auth.AuthProvider object.

The authentication provider to use for the request.

Output

A firebase.User instance.

Example

const authProvider = new firebase.auth.GoogleAuthProvider();

function* unlinkSaga() {
  try {
    const data = yield call(rsf.auth.unlink, authProvider);
    yield put(unlinkSuccess(data));
  }
  catch(error) {
    yield put(unlinkFailure(error));
  }
}

auth.updateEmail(email)
Generator

Updates the user's email.

Arguments

TypeDescription
email
Optional

String

The user's email.

Example

function* updateEmailSaga(email) {
  try {
    yield call(rsf.auth.updateEmail, email);
    yield put(updateEmail());
  }
  catch(error) {
    yield put(updateEmailFailure(error));
  }
}

auth.updatePassword(password)
Generator

Updates the user's password.

Arguments

TypeDescription
password
Optional

String

The user's password.

Example

function* updatePasswordSaga(password) {
  try {
    yield call(rsf.auth.updatePassword, password);
    yield put(updatePasswordSuccess());
  }
  catch(error) {
    yield put(updatePasswordFailure(error));
  }
}

auth.updateProfile(profile)
Generator

Updates the user's basic profile information.

Arguments

TypeDescription
profile
Optional

Object

The profile's displayName and photoURL to update. It can contain a displayName and a photoURL field, both are nullable strings.

Example

function* updateProfileSaga() {
  try {
    yield call(rsf.auth.updateProfile, {
      displayName: "Elon",
      photoURL: "elon@x.com"
    });
    yield put(updateProfileSuccess());
  }
  catch(error) {
    yield put(updateProfileFailure(error));
  }
}