Function useAuth

  • Read the authentication context.

    Returns AuthContextModel

    The current auth state and actions:

    • currentUser - the signed-in AuthUser, or null.
    • token - the raw JWT string, or null.
    • loading - true while a login/register request is in flight.
    • error - the last error message, or null.
    • login(username, password) - authenticate and store the session.
    • register(username, password) - create an account, then log in.
    • logout() - clear the session (server call is best-effort).

    If called outside of an AuthProvider.

    const { currentUser, login, logout } = useAuth();