All Projects → samuelgozi → Firebase Auth Lite

samuelgozi / Firebase Auth Lite

Licence: mit
A lightweight firebase auth alternative for the browser

Programming Languages

javascript
184084 projects - #8 most used programming language
es6
455 projects

Projects that are alternatives of or similar to Firebase Auth Lite

Heal O Chat
Heal-O-Chat is a Social Media Application for people who have been feeling less motivated in life or are losing hope. This platform allows users to chat with people and share their thoughts and feelings with each other and thereby let go of stress, anxiety, and depression that they've been feeling for long.
Stars: ✭ 42 (-58.42%)
Mutual labels:  firebase-auth
Simple firebase auth
Simple Firebase Login Flow in Flutter
Stars: ✭ 58 (-42.57%)
Mutual labels:  firebase-auth
Angular Redux Ngrx Examples
Sample projects with Angular (4.x) + Angular CLI + ngrx (Redux) + Firebase
Stars: ✭ 73 (-27.72%)
Mutual labels:  firebase-auth
Vue Firebase Starter
boilerplate of vue/vuex/vue(x)-router, with sass/prerendering, muse-ui, and firebase/firebaseui
Stars: ✭ 43 (-57.43%)
Mutual labels:  firebase-auth
Angular 4 Material Pos
POS written in Angular 4 with Angular Material UI
Stars: ✭ 54 (-46.53%)
Mutual labels:  firebase-auth
Firebaserealtimechat
Sample real-time chat application using Firebase
Stars: ✭ 60 (-40.59%)
Mutual labels:  firebase-auth
Gssoc2021 Hotelontouch
👨‍🔧👨‍🔧Manage your all hotel services at one place - This is the project repository for HotelOnTouch Project and this project is actively looking for new contributors👨‍🔧👩‍🏫
Stars: ✭ 30 (-70.3%)
Mutual labels:  firebase-auth
Nextjs Redux Firebase Authentication
Boilerplate Project for Authentication with Firebase in NextJs and Redux
Stars: ✭ 90 (-10.89%)
Mutual labels:  firebase-auth
Firebase As3
Integrate Firebase Auth, Realtime Database and Storage in your Adobe AIR projects.
Stars: ✭ 55 (-45.54%)
Mutual labels:  firebase-auth
Flutter twitter clone
Fully functional Twitter clone built in flutter framework using Firebase realtime database and storage
Stars: ✭ 1,123 (+1011.88%)
Mutual labels:  firebase-auth
Firebase auth ui
Flutter plugin for Firebase Auth UI. Supports popular auth providers by using native SDK for Android and iOS.
Stars: ✭ 44 (-56.44%)
Mutual labels:  firebase-auth
Firebase Admin Node
Firebase Admin Node.js SDK
Stars: ✭ 1,050 (+939.6%)
Mutual labels:  firebase-auth
Use Firebase Auth
A custom React Hook that provides a declarative interface for Firebase Auth.
Stars: ✭ 61 (-39.6%)
Mutual labels:  firebase-auth
Cocos2dx Cpp Sample
Firebase Cocos2d-x samples
Stars: ✭ 42 (-58.42%)
Mutual labels:  firebase-auth
The Road To React With Firebase
📓The Road to React with Firebase: Your journey to build business applications with React and Firebase.
Stars: ✭ 82 (-18.81%)
Mutual labels:  firebase-auth
Moveit
🚀 NLW #4 | React+ TypeScript + NextJS + StyledComponents + Firebase + MongoDb +Axios
Stars: ✭ 39 (-61.39%)
Mutual labels:  firebase-auth
Ionic Social Login With Firebase
IONIC - Social Login with Firebase
Stars: ✭ 58 (-42.57%)
Mutual labels:  firebase-auth
Gatsby Theme Firebase
🔥 A Gatsby Theme for adding Firebase to your application.
Stars: ✭ 96 (-4.95%)
Mutual labels:  firebase-auth
Sapper Graphql Firebase
Svelte + Sapper + GraphQL + Firebase Auth
Stars: ✭ 88 (-12.87%)
Mutual labels:  firebase-auth
Flutter firebase vote
A flutter application named Vote, based on firebase auth and firestore database.
Stars: ✭ 62 (-38.61%)
Mutual labels:  firebase-auth

Firebase auth lite (Beta) codecov bundlephobia

A performance focused alternative to the official firebase auth library that is designed to work with my other alternatives for storage and firestore.

The goal of this library is to provide a performance focused alternative to the official SDKs. This comes with some costs. The big one is browser support, we only support modern browsers, but you can always run them through Babel.

My Alternative SDK performs in average 13 times better and is 27 times smaller than the official ones.

What else do I need to consider?

The API is completely different. This is not a drop-in replacement, instead our API is much simpler and easier to use. In addition you should consider the next points:

  1. This is still work in progress and the API will change without warning until version 1.0.
  2. There is a small difference working with Federated Identity Providers.
  3. Sessions can only be persisted in localStorage (More options will be added).
  4. The code is written with modern JS and you are responsible for transpiling it for your targets, but babelrc configuration is ready. The code also makes use of the Fetch API and local storage.
  5. Not fully tested yet(I don't have a good testing strategy yet...)

Features and roadmap

  • [x] Authenticate with Email and password.

  • [x] Authenticate with Federated Identity Provider.

  • [x] Authenticate with link to email (no password required).

  • [x] Authenticate with a custom token.

  • [x] Authenticate anonymously.

  • [ ] Authenticate with phone.

  • [x] "Upgrade" anonymous accounts to any of the other ones.

  • [x] List all providers associated with an Email.

  • [x] Update Profile

  • [x] Reset password

  • [x] Verify email

  • [x] Delete the account.

The roadmap and progress to 1.0 can be seen at issue #2.

Setting up Federated identity providers

You might have noticed that when adding a Oauth Sign-in method in the firebase console, you are asked to add a URL that looks something like this to the Oauth's configurations: https://[app-id].firebaseapp.com/__/auth/handler

What you are essentially doing is whitelisting that URL, which is a hidden URL that exists in every firebase app. When using this library, you will need to add the URL of your app instead of the firebase's one. You need to add the URL of the page in your app that will handle the log in. You'll see what I mean in the docs below.

You might be curious as to why I'm avoiding using firebases endpoint, well, the reasons are:

  1. It is more secure. The reason you need to whitelist in the first place is for security.
  2. It is way faster, in some cases up to 5 seconds faster.
  3. I don't trust firebase (or anyone) with my user's private data, and you shouldn't either.

Yes, I know that the third one sounds exaggerated, especially when we rely on them anyways. But their endpoint works on the client (It's JS) and you shouldn't trust the client.

How to install

Once again i will say that its all still work in progress. Some things might break, and the API might change. However, I do encourage anyone to try it. I need feedback in order to improve it, so please use it and don't hesitate to leave feedback!

npm install firebase-auth-lite

or

yarn add firebase-auth-lite

After adding it to your dependencies instantiate.

import Auth from 'firebase-auth-lite';

// The multiple options can be seen in the API Reference,
// but only the apiKey is required across all auth flows.
const auth = new Auth({
	apiKey: '[The Firebase API key]'
});

Authenticate with email and password.

First instantiate Auth.

import Auth from 'firebase-auth-lite';

const auth = new Auth({
	apiKey: '[The Firebase API key]'
});

Then to sign-up use the signUp method. Please note that after a sign up, the user will be signed in automatically.

// Pass a new email and password.
auth.signUp('email', 'password');

In order to sign-in, pass the email and password to the signInWithPassword method.

auth.signIn('email', 'password');

If the data is correct and matches an existing user, the user will be signed in. Else, an error will be thrown with an explanation as to why.

Authenticate with Federated Identity Provider.

When signing in with an IdP, the user will be redirected to their page, and later redirected back into our app. Because of this, we need to tell the provider where to redirect to by using the redirectUri property. It needs to be a page that will finish the sign in flow by running a method (read below how).

Please make sure the provider is correctly set up in the Firebase console.

const auth = new Auth({
	apiKey: '[The Firebase API key]',
	redirectUri: 'http://example.com/auth'
});

// This function will run when the user click the sign in button.
function handleSignIn() {
	// This function will redirect the user out of our site, and into
	// the providers auth site. When the user finishes, he will then be
	// redirected into the `redirectUri` we have set in the `auth` instance.
	auth.signInWithProvider('google.com');
}

// Listen for the click, and run the sign in function.
document.getElementById('sign-in-google').addEventListener('click', handleSignIn);

The user will be redirected to http://example.com/auth, we need to make sure that we whitelisted this URL in the provider's settings. If not, we will receive an error with instructions on how to do so from the provider.

In that URL we need to finish the auth flow. We do that very easily by running a function. You can even do it on the same page you redirected from.

Authenticate with magic link (Email link).

To be able to do this, we need to send an OobCode to the users email, and then handle the user click on the link received.

const auth = new Auth({
	apiKey: '[The Firebase API key]',
	redirectUri: 'http://example.com/auth'
});

function loginWithEmail() {
	const email = document.getElementById('email-input').value;
	// We need to store somewhere the user email localy in order to validate that is the same user who clicked the email than the one who requested the email
	window.localStorage.setItem('loginEmail', email);

	// Then we request the email to be sent to the user
	auth.sendOobCode('EMAIL_SIGNIN', email)
}

// Listen for the click, and run the sign in function.
document.getElementById('sign-in').addEventListener('click', loginWithEmail);

In the email the user will receive an email who will redirect him to our previously defined redirectUri, in this case http://example.com/auth, we need to make sure that we whitelisted this URL in the provider's settings. If not, we will receive an error with instructions on how to do so from the provider.

In that URL we need to finish the auth flow. We do that very easily by running a function. You can even do it on the same page you redirected from.

async handleRedirect() {
	try {
		await auth.handleSignInRedirect({
			email: window.localStorage.getItem('loginEmail'),
		});
		window.localStorage.removeItem('loginEmail');

		// Do whatever you want with the newly logged in user
	} catch (error) {
		console.error(error);
	}
}

Authenticate anonymously.

You can authenticate a user anonymously with the same method used for email and password, just don't pass any arguments.

const auth = new Auth({
	apiKey: '[The Firebase API key]'
});

// That's all, really.
auth.signUp();

Listening for state changes

When working with reactive frameworks/libraries you will want to be able to tell when the user's data was updated. Its very easy to do with this library. in order to listen to state changes just call listen() with a callback:

const removeListener = auth.listen(user => {
	console.log(user); // Will log the user object.
});

removeListener(); // The callback will no longer be called on updates.

Now every time the user state or data is changed, the callback will be called with the new data. The listen() method returns a function that can be called when we wish to stop listening for updates.

Full API Reference

There are many more features, and they can be discovered by reading the full API reference. It can be found here: https://github.com/samuelgozi/firebase-auth-lite/wiki/API-Reference

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].