aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/oauth/oauth-token.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/oauth/oauth-token.ts')
-rw-r--r--server/models/oauth/oauth-token.ts59
1 files changed, 29 insertions, 30 deletions
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts
index 0d21c42fd..995fa33d5 100644
--- a/server/models/oauth/oauth-token.ts
+++ b/server/models/oauth/oauth-token.ts
@@ -1,4 +1,4 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2import { logger } from '../../helpers' 2import { logger } from '../../helpers'
3import { AccountModel } from '../account/account' 3import { AccountModel } from '../account/account'
4import { UserModel } from '../account/user' 4import { UserModel } from '../account/user'
@@ -15,6 +15,25 @@ export type OAuthTokenInfo = {
15 } 15 }
16} 16}
17 17
18enum ScopeNames {
19 WITH_ACCOUNT = 'WITH_ACCOUNT'
20}
21
22@Scopes({
23 [ScopeNames.WITH_ACCOUNT]: {
24 include: [
25 {
26 model: () => UserModel,
27 include: [
28 {
29 model: () => AccountModel,
30 required: true
31 }
32 ]
33 }
34 ]
35 }
36})
18@Table({ 37@Table({
19 tableName: 'oAuthToken', 38 tableName: 'oAuthToken',
20 indexes: [ 39 indexes: [
@@ -115,21 +134,10 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> {
115 const query = { 134 const query = {
116 where: { 135 where: {
117 accessToken: bearerToken 136 accessToken: bearerToken
118 }, 137 }
119 include: [
120 {
121 model: UserModel,
122 include: [
123 {
124 model: AccountModel,
125 required: true
126 }
127 ]
128 }
129 ]
130 } 138 }
131 139
132 return OAuthTokenModel.findOne(query).then(token => { 140 return OAuthTokenModel.scope(ScopeNames.WITH_ACCOUNT).findOne(query).then(token => {
133 if (token) token['user'] = token.User 141 if (token) token['user'] = token.User
134 142
135 return token 143 return token
@@ -140,24 +148,15 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> {
140 const query = { 148 const query = {
141 where: { 149 where: {
142 refreshToken: refreshToken 150 refreshToken: refreshToken
143 }, 151 }
144 include: [
145 {
146 model: UserModel,
147 include: [
148 {
149 model: AccountModel,
150 required: true
151 }
152 ]
153 }
154 ]
155 } 152 }
156 153
157 return OAuthTokenModel.findOne(query).then(token => { 154 return OAuthTokenModel.scope(ScopeNames.WITH_ACCOUNT)
158 token['user'] = token.User 155 .findOne(query)
156 .then(token => {
157 token['user'] = token.User
159 158
160 return token 159 return token
161 }) 160 })
162 } 161 }
163} 162}