feat: user profile fetch info + groups
This commit is contained in:
@@ -26,6 +26,24 @@ module.exports = {
|
||||
usr.password = ''
|
||||
usr.tfaSecret = ''
|
||||
return usr
|
||||
},
|
||||
async profile (obj, args, context, info) {
|
||||
if (!context.req.user || context.req.user.id < 1 || context.req.user.id === 2) {
|
||||
throw new WIKI.Error.AuthRequired()
|
||||
}
|
||||
const usr = await WIKI.models.users.query().findById(context.req.user.id)
|
||||
if (!usr.isActive) {
|
||||
throw new WIKI.Error.AuthAccountBanned()
|
||||
}
|
||||
const usrGroups = await usr.$relatedQuery('groups')
|
||||
return {
|
||||
...usr,
|
||||
password: '',
|
||||
providerKey: '',
|
||||
tfaSecret: '',
|
||||
lastLoginOn: '1970-01-01',
|
||||
groups: usrGroups.map(g => g.name)
|
||||
}
|
||||
}
|
||||
},
|
||||
UserMutation: {
|
||||
|
@@ -27,6 +27,8 @@ type UserQuery {
|
||||
single(
|
||||
id: Int!
|
||||
): User @auth(requires: ["manage:users", "manage:system"])
|
||||
|
||||
profile: UserProfile
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
@@ -110,3 +112,19 @@ type User {
|
||||
updatedAt: Date!
|
||||
groups: [Group]!
|
||||
}
|
||||
|
||||
type UserProfile {
|
||||
id: Int!
|
||||
name: String!
|
||||
email: String!
|
||||
providerName: String
|
||||
isSystem: Boolean!
|
||||
isVerified: Boolean!
|
||||
location: String!
|
||||
jobTitle: String!
|
||||
timezone: String!
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
lastLoginOn: Date!
|
||||
groups: [String]!
|
||||
}
|
||||
|
@@ -69,6 +69,10 @@ module.exports = {
|
||||
message: 'You are not authorized to register. Your domain is not whitelisted.',
|
||||
code: 1011
|
||||
}),
|
||||
AuthRequired: CustomError('AuthRequired', {
|
||||
message: 'You must be authenticated to access this resource.',
|
||||
code: 1019
|
||||
}),
|
||||
AuthTFAFailed: CustomError('AuthTFAFailed', {
|
||||
message: 'Incorrect TFA Security Code.',
|
||||
code: 1005
|
||||
|
Reference in New Issue
Block a user