How to store login settings when creating a new app (that integrates with an api)

Hi

It’s my first time creating an app and I have a question.
When using the login window, I’d like to store the login credentials in the (homey)settings.

But I don’t know how, I’ve tried already to add these fields (username and password) in the driver.compose file.

"settings": [
        {
            "id": "username",
            "type": "text",
            "label": {
                "en": "WEN username"
            }
        },
        {
            "id": "password",
            "type": "password",
            "label": {
                "en": "WEM password"
            }
        }
    ]

The SDK has a settings section but I’m not getting there.

This was my try on storing the credentials but that did not work out

               this.homey.settings.setSettings(username, data.username);
                this.homey.settings.setSettings(password, data.password);

The error that I’m getting is TypeError: this.homey.settings.setSettings is not a function

Any suggestions here?

Use
this.homey.settings.set('username', data.username);

notice also the username is a string so add the quotes.
The other thing to be aware of is that the device data (if obtained using this.getData()) is read only, so you won’t be able to charge that after pairing. Therefore I recommend you store username and password in the settings when the device is add and not the data.

Hi Adrian

Thanks for the suggestion, everything is up and running!

1 Like

I’m trying to do the exact same thing for global app settings, but I can’t figure out my mistake.
I built a very basic index.html, settings are stored and well dispayed.
But using this:

'use strict';
const Homey = require('homey');
class MyApp extends Homey.App {

	onInit() {
		const timer = this.homey.settings.get('timer');
	}

give me this error:

─────────────── Logging stdout & stderr ───────────────
/app.js:11
                const timer = this.homey.settings.get('timer');
                                         ^
TypeError: Cannot read property 'settings' of undefined
    at MyApp.onInit (/app.js:11:28)
    at /opt/homey-client/node_modules/homey-apps-sdk-v2/lib/SDK.js:216:31
    at FSReqCallback.oncomplete (fs.js:167:5)

Any help will be welcome.

Use SDKv3, not SDKv2.

Off course, thanks a lot.