Introduce account document to user document

An account document is attached to a user document if an account of the
user is on the server. It may be missing if the user is on a remote server.
This commit is contained in:
Akihiko Odaki 2018-03-26 00:19:07 +09:00
parent a633f184ab
commit 19b9cb105d
70 changed files with 355 additions and 280 deletions

View file

@ -39,10 +39,10 @@ module.exports = (app: express.Application) => {
if (userToken == null) return res.send('plz signin');
const user = await User.findOneAndUpdate({
token: userToken
'account.token': userToken
}, {
$set: {
twitter: null
'account.twitter': null
}
});
@ -126,7 +126,7 @@ module.exports = (app: express.Application) => {
const result = await twAuth.done(JSON.parse(ctx), req.query.oauth_verifier);
const user = await User.findOne({
'twitter.user_id': result.userId
'account.twitter.user_id': result.userId
});
if (user == null) {
@ -148,10 +148,10 @@ module.exports = (app: express.Application) => {
const result = await twAuth.done(JSON.parse(ctx), verifier);
const user = await User.findOneAndUpdate({
token: userToken
'account.token': userToken
}, {
$set: {
twitter: {
'account.twitter': {
access_token: result.accessToken,
access_token_secret: result.accessTokenSecret,
user_id: result.userId,