From a1fd088c03cb1bcaa9f779a31ddb51d5d8fb5303 Mon Sep 17 00:00:00 2001 From: bugss Date: Thu, 1 Jun 2017 10:44:49 +0800 Subject: [PATCH] docs:Less service attribute (#7) --- README.md | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3405d1e..9d15176 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,10 @@ $ npm i egg-userservice - `ctx.user`: current user data - `ctx.userId`: the user id of current user +- `app.config.userservice.service.getUser(ctx)`: +- `app.config.userservice.service.getUserId(ctx)`: + + ## Configuration @@ -59,18 +63,24 @@ Add your userservice configurations to `config/config.default.js` ```js exports.userservice = { - * getUser(ctx) { - // Retrieve your user data from cookie, redis, db, whatever - // For common web applications using cookie, you may get session id with ctx.cookies - }, - - getUserId(ctx) { - // The way to get userId - // eg. return ctx.user.userId + service: { + * getUser(ctx) { + // Retrieve your user data from cookie, redis, db, whatever + // For common web applications using cookie, you may get session id with ctx.cookies + }, + + getUserId(ctx) { + // The way to get userId + // eg. return ctx.user.userId + } } } ``` + + + + ## For complicated applications The way your application retrieving user data can be complicated, it may be very weird