nestdotland / nest

[WIP] πŸ₯š Nest CLI
https://docs.nest.land/cli
MIT License
7 stars 2 forks source link

feat: use WebStorage API for internal data #22

Open maximousblk opened 3 years ago

maximousblk commented 3 years ago

πŸš€ Feature

All the info that should not be view or edited by the user should be stored in localstorage.

Motivation

Deno added support for WebStorage API

blog post: https://deno.com/blog/v1.10#support-for-web-storage-api

This would also make the code a bit cleaner since we won't have to poke the environment variables to find the home directory just to get the user's access token.

pr: https://github.com/denoland/deno/pull/7819

Implementation

The user would define the location during install like so:

deno install -qA --unstable --location https://nest.land https://nest.land/-/nest/nest.ts

and used like so:

// Add new user (nest login)
addUser(username: string, token: string) {
  const users: Users = JSON.parse(localStorage.getItem('users'));

  users[username] = { token }

  localStorage.setItem('users', JSON.stringify(users);
}

addUser('maximousblk', 'NEST_6FF4C8F4374F46C5A5928AFE85C2354EA37AED00')

// Change active user (nest switch)
setActiveUser(username: string) {
  localStorage.setItem('activeUser', username);
}

setActiveUser('maximousblk')

Alternatives

n/a

Additional context

n/a