0.0.10 • Published 2 years ago

ellenox-firebase-auth v0.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

ellenox-firebase-auth 🔥

Provides ready to use Google button and Phone auth functions for authentication in expo-firebase projects.

Prerequisites

⚠️ Peer Dependencies

This component has a peer dependency on expo-auth-session. expo-auth-session has to be installed and linked into your project. Follow expo-auth-session to install the dependency.

This component has a peer dependency on firebase. firebase has to be installed and linked into your project. Follow firebase to install the dependency.

Installation

Supported version: react-native >= 0.59.0

npm install ellenox-firebase-auth

or

yarn add ellenox-firebase-auth

Example

Sign in with google

import { GoogleButton } from 'ellenox-firebase-auth';

....

<GoogleButton
  auth={auth} // const auth = getAuth(app);
  config={{
    expoClientId: WEB_CLIENT_ID,
    androidClientId: STANDALONE_ANDROID_CLIENT_ID,
    iosClientId: STANDALONE_IOS_CLIENT_ID,
  }}
  title={"Continue with Google"}
  handleError={(error) => console.log(error)}
  handleSuccess={(response) => console.log(response)}
  loaderColor="red"
/>

Sign in with phone number

import { sendOTPToPhoneNumber, signInWithPhoneNumber } from 'ellenox-firebase-auth';
import { FirebaseRecaptchaVerifierModal } from "expo-firebase-recaptcha";

....

const LoginScreen = () => {
  const recaptchaVerifier = useRef(null);
  const [verificationId, setVerificationId] = useState("");

  const sendOTPHandler = () => {
    sendOTPToPhoneNumber(
      auth,
      "+911234567890",
      recaptchaVerifier,
      handleOTPSuccess,
      handleOTPError
    );
  };

  const handleOTPSuccess = (responseId) => {
    setVerificationId(responseId);
  };

  const handleOTPError = (error) => {
    console.log(error);
  };

  const signInHandler = () => {
    signInWithPhoneNumber(
      auth,
      verificationId,
      OTP,
      handleSuccess,
      handleError
    );
  }

  return (
    <>
      <FirebaseRecaptchaVerifierModal
        ref={recaptchaVerifier}
        firebaseConfig={firebaseConfig} // your firebase config
        attemptInvisibleVerification={false}
      />
      <Button
        title={"Get OTP"}
        onPress={sendOTPHandler}
      />
      <Button
        title={"Verify and Sign in"}
        onPress={signInHandler}
      />
    <>
  )
}

Props

GoogleButton Props

PropDescriptionTypeDefault ValueRequired
authyour project app authFirebase Authundefinedtrue
configgoogle config ids for different platformsGoogle Configundefinedtrue
iconlocal path to google iconImageSourcePropType'https://cdn-icons-png.flaticon.com/512/2991/2991148.png'false
loaderColorcolor to show when loadingString'#000'false
titletitle of buttonStringundefinedtrue
buttonStylecustom style for ViewViewStylefalse
containerStylecustom style for TouchableOpacityViewStylefalse
iconStylecustom style for google iconImageStylefalse
textStylecustom style for button textTextStylefalse
handleErrorcallback for google authentication errorFunctionundefinedtrue
handlePresscallback for google button pressFunction() => {}false
handleSuccesscallback for google authentication successFunctionundefinedtrue

sendOTPToPhoneNumber Params

ParamDescriptionTypeDefault ValueRequired
authyour project app authFirebase Authtrue
phoneNumbervalid phone number with country codeStringtrue
recaptchaVerifierrecaptcha referenceReferencetrue
handleSuccesscallback for phone number verification successFunctionfalse
handleErrorcallback for phone number verification errorFunctionfalse

signInWithPhoneNumber Params

ParamDescriptionTypeDefault ValueRequired
authyour project app authFirebase Authtrue
verificationIdverification id when phone number is verifiedStringtrue
verificationCodeotp sent to phone numberStringtrue
handleSuccesscallback for phone authentication successFunctionfalse
handleErrorcallback for phone authentication errorFunctionfalse

License

This project is licensed under the ISC License.

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago