0.0.13 • Published 2 years ago

@winwin/koa-simple-account v0.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

koa-simple-account

Why?

Sometimes I just need a simple account system, and this is the implementation.

How to use?

/** SETUP **/
const app = new Koa();
// Your koa app instance.

const account = createAccount({
  path: path.resolve(__dirname, "../data/account.db"),
  // path for database
  secret: "secret",
  // jwt secret
  expiresIn: "10min",
  // access token expire time
  refreshableIn: "7d",
  // refresh token expire time
});

app.use(account.middleware);
// This provide auth routes.
// If you want to mount it to aother route, use `koa-mount`.

/** USAGE **/
const router = new Router();
// Your koa router
router.get("/protected-by-access-token", account.auth(), (ctx) => {
  // Some routes require access token.
  // Do something then ...
});
router.get("/protected-by-refresh-token", account.auth("refresh"), (ctx) => {
  // Some routes require refresh token.
  // Do something then ...
});

Integrate with web

The simple way is to use @winwin/vue-simple-account.

Or you can:

  • POST /signin with basic authentication, get access token and refresh token.
  • POST /signout with authentication header: BEARER ${accessToken} to signout.
  • POST /refresh with refresh token to refresh tokens.
  • GET /info with access token to get username.
  • PUT /info with username,password in request body to update user info.
0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago