Authentication

Web Chat Core SDK Authentication

Login or Register with and email ID and password.

Applozic creates a new user if the user doesn't exists.

Login a User

client.login('[email protected]', 'user-password');

Sample Code

import { useMutation, useQueryClient } from "react-query";
import { useApplozicClient } from "../../providers/useApplozicClient";
import { LoginResult } from "@applozic/core-sdk";
import { useToast } from "@chakra-ui/react";

function useUserLogin() {
  const { client, loginResult } = useApplozicClient();
  const queryClient = useQueryClient();
  const toast = useToast();
  return useMutation(
    async ({ email, password }: { email: string; password: string }) => {
      return await client?.login(email, password);
    },
    {
      onSuccess: (data) => {
        if ((data as any) === "INVALID_APPID") {
          queryClient.setQueryData<LoginResult | null>(
            ["self"],
            null
          );
          toast({
            title: "Error logging in",
            description: (data as any).toString(),
            status: "error",
          });
        } else {
          if (data) {
            queryClient.setQueryData<LoginResult>(["self"], data);
          }
        }
      },
    }
  );
}

export default useUserLogin;

What’s Next
Did this page help you?