Skip to content

kingRayhan/fireauth-9-cookbook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

Firebase 9, authentication

Initialization

import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";

const config = {
  apiKey: "xxxx",
  authDomain: "xxxx",
  projectId: "xxxx",
  storageBucket: "xxxx",
  messagingSenderId: "xxxx",
  appId: "xxxx",
};


export const app = initializeApp(config);
export const auth = getAuth(app);

Create User

import { createUserWithEmailAndPassword } from 'firebase/auth';

await createUserWithEmailAndPassword(
  auth,
  email,
  password,
)

Signin using email and password

import { signInWithEmailAndPassword } from 'firebase/auth';

await signInWithEmailAndPassword(
  auth,
  email,
  password,
)

Signin with popup -> Social login

import { GoogleAuthProvider, signInWithPopup } from "firebase/auth";

export const auth = getAuth(app);

const provider = new GoogleAuthProvider();
signInWithPopup(auth, provider).then((res) => {
  console.log(res);
});

Authenticated user observer

import { onAuthStateChanged } from "firebase/auth";

onAuthStateChanged(auth, (user) => {
  if (user) {
    // User is signed in, see docs for a list of available properties
    // https://firebase.google.com/docs/reference/js/firebase.User
    const uid = user.uid;
    // ...
  } else {
    // User is signed out
    // ...
  }
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published