Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nativescript storing user tokens

Tags:

nativescript

Is it a good practice or am i missing something? I wan't to store user access and refresh token returned from a Web API in application-settings or do we have password vault equivalent in nativescript or do we use sql lite My requirement is that my tokens should not be allowed to access by other apps installed on device. Thanks for the help in advance Regards

like image 422
Atul Chaudhary Avatar asked Aug 26 '15 05:08

Atul Chaudhary


1 Answers

If you just want to store a simple string, only accessible by the app itself (and no other app), using the Application Settings is the way to go.

var appSettings = require('application-settings');

// Trying to get a string which is not set yet
var token = appSettings.getString('token', 'defaultValue');
console.log(token); // defaultValue

// Setting the string
appSettings.setString('token', 'abc123');

// Getting the string
token = appSettings.getString('token', 'defaultValue');
console.log(token); // abc123

There's no vault (yet?).

If you want to store some more database-like data, there's a sqlite module available, however, for only storing a simple string or two, this would be way overkill and I'd go for the application-settings way described above.

https://www.npmjs.com/package/nativescript-sqlite

like image 162
Emil Oberg Avatar answered Nov 14 '22 09:11

Emil Oberg