naystack - v1.5.10
    Preparing search index...

    Function useLogin

    • Returns a login function that PUTs to the auth endpoint with credentials. On success, the response's accessToken is stored and the token context updates automatically.

      Returns (data: object) => Promise<string | null>

      A function (data) => Promise<null | string>. Call with { email, password }. Returns null on success, or the error message on failure (e.g. "Invalid password").

      import { useLogin } from "naystack/auth/client";

      function LoginForm() {
      const login = useLogin();

      const handleSubmit = async (data: { email: string; password: string }) => {
      const error = await login(data);
      if (error) {
      form.setError("password", { message: error });
      } else {
      router.replace("/dashboard");
      }
      };
      }