npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mayo-firebase-auth

v1.6.1

Published

The context of using this package is: - You have a react-native app - You need to do google authentication - You need to cache the connected user to avoid requesting login every time - You need to save in a firestore db the last connection date.

Downloads

45

Readme

The context of using this package is:

  • You have a react-native app
  • You need to do google authentication
  • You need to cache the connected user to avoid requesting login every time
  • You need to save in a firestore db the last connection date.

Basically, you just have to import the library, wrap your app and navigate to the SignIn screen provided by the library.

And then, after login, an event 'signedIn' is emitted, that you can catch to describe what should be done on successfull login.

Here I am showing you all the things to do :

## Install

  # use yarn, it is faster and safer
  yarn add mayo-firebase-auth @react-native-google-signin/google-signin
  npx pod-install

Firebase configuration

  • Connect to firebase, create a project and an iOS application.
  • Export GoogleService-Info.plist and import it in your app/ios folder

Update Info.plist to add these parameters:

  • Add CLIENT_ID:
	<key>GIDClientID</key>
	<string>XXXXXXXXXXXX.apps.googleusercontent.com</string>
  • Add REVERSED_CLIENT_ID:
  <key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>com.googleusercontent.apps.XXXXXXXXXXXXXXXXX</string>
			</array>
		</dict>
	</array>

Create a firebaseConfig.json file:

The parameters value are picked from GoogleService-Info.plist and app in the firebase console.

const conf = {
  apiKey: 'XXXX',
  authDomain: 'XXXXXX.firebaseapp.com',
  projectId: 'XXXXXX',
  storageBucket: 'XXXXXX.appspot.com',
  messagingSenderId: 'XXXXXX',
  appId: '1:XXXXXX',
  databaseURL: '',
  measurementId: 'XXXXXX',
};

export {conf};

Usage:

HomeScreen.tsx :

  import { useLogout, UserContext, UserContextType } from 'mayo-firebase-auth';
  const HomeScreen = () => {
    const { authEvents } = useContext(UserContext) as UserContextType;
    const navigation = useNavigation<NavigationProp<RootStackParamList, 'SignIn'>>();

    const { performLogout } = useLogout();
    useEffect(() => {
      const onSignedOut = async () => {
        navigation.navigate('SignIn');
      };
      
      authEvents.on('signedOut', onSignedOut);
      return () => authEvents.off('signedOut', onSignedOut);
    }, []);
  }

InitialScreen.tsx :

  import { UserContext, UserContextType } from 'mayo-firebase-auth';
  const InitialScreen = () => {
    const { user, setUser, authEvents, userContextLoading } = useContext(UserContext) as UserContextType;
    const navigation = useNavigation<NavigationProp<RootStackParamList>>();

    useEffect(() => {
        if(!userContextLoading) navigation.navigate(user ? 'Home':'SignIn');
    }, [user]);

    useEffect(() => {
      const onSignedIn = async (googleCredentials) => {
        if(!googleCredentials) throw Error('InitialScreen - Trying to firebase signIn without googleCredentials !');
        const newUser = await signInFirebase(googleCredentials);
        if(!newUser) throw Error('InitialScreen - Firebase sign do not return any user !');
        setUser(newUser);
      };
      authEvents.on('signedIn', onSignedIn);

      return () => {
        authEvents.off('signedIn', onSignedIn);
      };
    }, []);

    return null;
  };

AppNavigator.tsx:

  import { SignInScreen, UserProvider } from 'mayo-firebase-auth';

  export const MainApp: React.FC = () => {
    // For android WebClientId is mandatory. Also don't forget to add the SHA key in firebase console
    const webClientId = "XXXXXXXX.apps.googleusercontent.com";

    return (

      <NavigationContainer>
        <UserProvider>
            <Stack.Navigator>
              <Stack.Screen name="Login" component={InitialScreen}/>
              <Stack.Screen name="SignIn" component={SignInScreen} 
                initialParams={{ webClientId }}
              />
              <Stack.Screen name="Home" component={HomeScreen} />
            </Stack.Navigator>
        </UserProvider>
      </NavigationContainer>
      );
    }

📚 License

This project is licensed under the MIT License.