How to use the teslajs.loginAsync function in teslajs

To help you get started, we’ve selected a few teslajs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mseminatore / alexa-tesla / index.js View on Github external
// if we already have vehicles and options then the promise is fulfilled
    if (vehicles && options) {
        log("Found existing vehicle session info");
        return new Promise(function (fulfill, reject) {
            fulfill(vehicles);
        });
    } else {
        // otherwise we need to get the vehicle information
        log("No existing session info found!");

        // if user/pass provided then login
        if (username && password) {
            log("username/pwd found");

            return tjs.loginAsync(username, password)
            .then(function(result) {
                options = {authToken: result.authToken};
                return tjs.vehiclesAsync(options);
            })
            .then(function(vehicles) {
                // ensure we have a default vehicle
                options.vehicleID = vehicles[0].id_s;
                session.set("vehicles", vehicles);
                session.set("options", options);
                return vehicles;
            });
        } else if (token) {
            // if token found in ENV then use it
            log("OAuth token found in process ENV");

            options = {authToken: token};