Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add signOut? #29

Open
Nithur-M opened this issue Jun 30, 2021 · 1 comment
Open

How to add signOut? #29

Nithur-M opened this issue Jun 30, 2021 · 1 comment

Comments

@Nithur-M
Copy link

Hi, can you let me know how to sign user out after creating user with email?. I want the user to verify his email before using the app.
I used auth().signOut() but it isn't working.

@UrvaSuthar
Copy link

import { getAuth, signOut } from 'firebase/auth';
import { initializeApp } from 'firebase/app';

// Initialize Firebase app with configuration
const app = initializeApp({
  // Add your Firebase configuration here
  apiKey: 'your-api-key',
  authDomain: 'your-auth-domain',
  projectId: 'your-project-id',
  // ...
});

// Create the authentication instance
const auth = getAuth(app);

// Function to handle sign out
const handleSignOut = () => {
  signOut(auth)
    .then(() => {
      // Sign out successful
      console.log('User signed out successfully.');
    })
    .catch((error) => {
      // An error occurred during sign out
      console.error('Error signing out:', error);
    });
};

// Render the sign out button in your React component
const MyComponent = () => {
  return (
    <button onClick={handleSignOut}>Sign Out</button>
  );
};

export default MyComponent;

This code snippet demonstrates importing getAuth and signOut from firebase/auth. It initializes the Firebase app with your configuration, creates an authentication instance, and defines a handleSignOut function that calls signOut(auth) to sign out the user.

You can use the handleSignOut function as the onClick event handler for your sign-out button. In this example, the button is rendered within a React component called MyComponent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants