Adamite
  • Initial page
  • Server
    • Introduction
    • Database
      • Configuration
      • Using different adapters
        • Memory Adapter
      • Securing your data
        • Securing read operations
    • Functions
      • Invokable Functions
      • Runtime Functions
      • Scheduled Functions
  • SDK
    • Introduction
    • Database
      • Introduction
      • Read a document
      • Read multiple documents
      • Subscribe to changes
      • Create a new document
      • Update an existing document
      • Delete a document
    • Authentication
      • Create a user
      • Log in and log out
      • Get the logged in user
    • Functions
      • Invoke a function
Powered by GitBook
On this page

Was this helpful?

  1. SDK
  2. Authentication

Get the logged in user

At any time, you can use the currentUser property to get the signed in user.

const currentUser = adamite().auth().currentUser;
const userId = currentUser.id;

You can also subscribe to changes to the auth state using the onAuthStateChange method.

adamite().auth().onAuthStateChange(currentUser => {
  if (currentUser) {
    console.log("logged in as " + currentUser.id);
  } else {
    console.log("not logged in");
  }
});

The onAuthStateChange method returns a function that can be called to unsubscribe from auth state changes.

const unsubscribe = adamite().auth().onAuthStateChange(currentUser => {
  // ...
});

unsubscribe();
PreviousLog in and log outNextFunctions

Last updated 5 years ago

Was this helpful?