AuthenticationResult

You can supply two callback functions to the AuthenticationResult authenticated and notAuthenticated, each will be passed the KeycloakInstance.

Signature:

{
    auth: KeycloakInstance,
    isAuthenticated: boolean,
    authenticated: (onAuthenticated: (auth: KeycloakInstance) => void) => AuthenticationResult;
    notAuthenticated: (onNotAuthenticated: (auth: KeycloakInstance) => void) => AuthenticationResult;
}

Parameters:

ParameterRequiredDescription
authenticatedTruea callback function to be executed when the user is authenticated after the call.
notAuthenticatedTruea callback function to be executed when the user is not authenticated after the call.

Example:

// Check if a user is authenticated.
venlyConnect.checkAuthenticated()
            .then((result) => result.authenticated((auth) => {
                                        console.log('The user is authenticated: ' + auth.subject);
                                     })
                                     .notAuthenticated((auth) => {
                                        console.log('The user is not authenticated');
                                     })
             );

// Check if a user is authenticated. If not, show the login form
venlyConnect.authenticate()
            .then((result) => result.authenticated((auth) => {
                                       console.log('The user is authenticated: '  + auth.subject);
                                    })
                                    .notAuthenticated((auth) => {
                                       console.log('The user is not authenticated');
                                    })
            );