SDK Reference
react
authenticate

authenticate Method

Authenticate user with idToken received from Google OAuth2.

Parameters

  • idToken - Token received from Google OAuth2.
  • callback - Callback function to be called after authentication. This function contains two parameters:
    • result - if authentication is successful.
    • error - Error message if any.

If the user does not have a wallet, a wallet prompt will be shown to the user to create a wallet.

authenticate (
  idToken: string,
  callback: (result: any, error: any) => void
) => void;

Example

import {
  useOkto,
  type OktoContextType,
} from 'okto-sdk-react';
 
const { authenticate } = useOkto() as OktoContextType;
const idToken = 'USER_ID_TOKEN';
authenticate(idToken, (result, error) => {
    if (result) {
        console.log('authentication successful');
    }
    if (error) {
        console.error('authentication error:', error);
    }
});