diff --git a/packages/server-core/src/hooks/channel-permission-authenticate.ts b/packages/server-core/src/hooks/channel-permission-authenticate.ts index f9438ef732..07ad83f12e 100755 --- a/packages/server-core/src/hooks/channel-permission-authenticate.ts +++ b/packages/server-core/src/hooks/channel-permission-authenticate.ts @@ -1,15 +1,14 @@ import { BadRequest, Forbidden } from '@feathersjs/errors' import { HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' import { Application } from './../../declarations.d' // This will attach the owner ID in the contact while creating/updating list item export default () => { return async (context: HookContext): Promise => { const { params, app } = context - console.log(params.query) - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params.user as UserDataType const userId = loggedInUser.id if (!params.query!.channelId) { throw new BadRequest('Must provide a channel ID') diff --git a/packages/server-core/src/hooks/create-group-owner.ts b/packages/server-core/src/hooks/create-group-owner.ts index 5a96f24c32..e2a5f8e0bc 100755 --- a/packages/server-core/src/hooks/create-group-owner.ts +++ b/packages/server-core/src/hooks/create-group-owner.ts @@ -1,13 +1,13 @@ import { HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' // This will attach the owner ID in the contact while creating/updating list item export default () => { return async (context: HookContext): Promise => { // Getting logged in user and attaching owner of user - const { result } = context - const loggedInUser = extractLoggedInUserFromParams(context.params) + const { result, params } = context + const loggedInUser = params.user as UserDataType await context.app.service('group-user').create({ groupId: result.id, groupUserRank: 'owner', diff --git a/packages/server-core/src/hooks/create-party-owner.ts b/packages/server-core/src/hooks/create-party-owner.ts index 672e2d08e9..48e7160bb5 100755 --- a/packages/server-core/src/hooks/create-party-owner.ts +++ b/packages/server-core/src/hooks/create-party-owner.ts @@ -1,14 +1,12 @@ import { HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' - // This will attach the owner ID in the contact while creating/updating list item export default () => { return async (context: HookContext): Promise => { // Getting logged in user and attaching owner of user - const { result } = context + const { result, params } = context - const user = extractLoggedInUserFromParams(context.params) + const user = params.user // TODO: add location_admins type // as User let ownerUser = false if (user.location_admins) { ownerUser = diff --git a/packages/server-core/src/hooks/group-permission-authenticate.ts b/packages/server-core/src/hooks/group-permission-authenticate.ts index 83c93cc2b6..052622ec79 100755 --- a/packages/server-core/src/hooks/group-permission-authenticate.ts +++ b/packages/server-core/src/hooks/group-permission-authenticate.ts @@ -1,14 +1,14 @@ import { BadRequest, Forbidden } from '@feathersjs/errors' import { HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' // This will attach the owner ID in the contact while creating/updating list item export default () => { return async (context: HookContext): Promise => { let fetchedGroupId const { id, method, params, app, path } = context - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params.user as UserDataType if (path === 'group-user' && method === 'remove') { const groupUser = await app.service('group-user').get(id!, null!) fetchedGroupId = groupUser.groupId diff --git a/packages/server-core/src/hooks/group-user-permission-authenticate.ts b/packages/server-core/src/hooks/group-user-permission-authenticate.ts index 5b13ae4de0..26ffdc5fb2 100755 --- a/packages/server-core/src/hooks/group-user-permission-authenticate.ts +++ b/packages/server-core/src/hooks/group-user-permission-authenticate.ts @@ -1,15 +1,14 @@ import { BadRequest } from '@feathersjs/errors' import { HookContext } from '@feathersjs/feathers' -import { Params } from '@feathersjs/feathers' import _ from 'lodash' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' // This will attach the owner ID in the contact while creating/updating list item export default () => { return async (context: HookContext): Promise => { const { params, app } = context - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params.user as UserDataType const groupId = params.query!.groupId const userId = params.query!.userId || loggedInUser.id const paramsClone = _.cloneDeep(context.params) diff --git a/packages/server-core/src/hooks/invite-remove-authenticate.ts b/packages/server-core/src/hooks/invite-remove-authenticate.ts index c5bf21dfe9..880322b8c7 100755 --- a/packages/server-core/src/hooks/invite-remove-authenticate.ts +++ b/packages/server-core/src/hooks/invite-remove-authenticate.ts @@ -4,7 +4,7 @@ import { HookContext } from '@feathersjs/feathers' import { IdentityProviderInterface } from '@xrengine/common/src/dbmodels/IdentityProvider' import Paginated from '../types/PageObject' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' // This will attach the owner ID in the contact while creating/updating list item export default () => { @@ -12,7 +12,7 @@ export default () => { let inviteIdentityProviderUser // Getting logged in user and attaching owner of user const { id, params, app } = context - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params.user as UserDataType const invite = await app.service('invite').get(id!) if (invite == null) { throw new BadRequest('Invalid invite ID') diff --git a/packages/server-core/src/hooks/matchmaking-restrict-multiple-queueing.ts b/packages/server-core/src/hooks/matchmaking-restrict-multiple-queueing.ts index 7436255c2f..cbb995d464 100644 --- a/packages/server-core/src/hooks/matchmaking-restrict-multiple-queueing.ts +++ b/packages/server-core/src/hooks/matchmaking-restrict-multiple-queueing.ts @@ -1,15 +1,15 @@ import { BadRequest } from '@feathersjs/errors' import { Hook, HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' /** * prevent user to join new search game more then once at time */ export default (): Hook => { return async (context: HookContext): Promise => { - const { app } = context - const loggedInUser = extractLoggedInUserFromParams(context.params) + const { app, params } = context + const loggedInUser = params.user as UserDataType const matchUserResult = await app.service('match-user').find({ query: { userId: loggedInUser.id, diff --git a/packages/server-core/src/hooks/matchmaking-save-ticket.ts b/packages/server-core/src/hooks/matchmaking-save-ticket.ts index 1d36961fcf..2202ff9dc6 100644 --- a/packages/server-core/src/hooks/matchmaking-save-ticket.ts +++ b/packages/server-core/src/hooks/matchmaking-save-ticket.ts @@ -1,12 +1,11 @@ import { Hook, HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' export default (): Hook => { return async (context: HookContext): Promise => { - const { app, result, data } = context - - const loggedInUser = extractLoggedInUserFromParams(context.params) + const { app, result, data, params } = context + const loggedInUser = params.user as UserDataType await app.service('match-user').create({ ticketId: result.id, gamemode: data.gamemode, diff --git a/packages/server-core/src/hooks/message-permission-authenticate.ts b/packages/server-core/src/hooks/message-permission-authenticate.ts index ffd5a22ab3..daed014d62 100755 --- a/packages/server-core/src/hooks/message-permission-authenticate.ts +++ b/packages/server-core/src/hooks/message-permission-authenticate.ts @@ -1,14 +1,14 @@ import { BadRequest } from '@feathersjs/errors' import { HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' import { Application } from './../../declarations.d' // This will attach the owner ID in the contact while creating/updating list item export default () => { return async (context: HookContext): Promise => { const { id, method, data, params, app } = context - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params.user as UserDataType if (method === 'remove' || method === 'patch') { const match = await app.service('message').Model.findOne({ where: { diff --git a/packages/server-core/src/hooks/party-permission-authenticate.ts b/packages/server-core/src/hooks/party-permission-authenticate.ts index e1422b808b..015de06c9e 100755 --- a/packages/server-core/src/hooks/party-permission-authenticate.ts +++ b/packages/server-core/src/hooks/party-permission-authenticate.ts @@ -2,7 +2,7 @@ import { BadRequest, Forbidden } from '@feathersjs/errors' import { HookContext } from '@feathersjs/feathers' import _ from 'lodash' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' // This will attach the owner ID in the contact while creating/updating list item export default () => { @@ -10,7 +10,7 @@ export default () => { try { let fetchedPartyId const { id, data, method, params, app, path } = context - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params.user as UserDataType if (path === 'party-user' && method === 'remove') { const partyUser = await app.service('party-user').get(id!) fetchedPartyId = partyUser.partyId @@ -38,7 +38,7 @@ export default () => { if (isAdmin != null) { data.isOwner = 1 } - await app.service('user').patch(loggedInUser.id, { + await app.service('user').patch(loggedInUser.id!, { partyId: data.partyId }) } else { diff --git a/packages/server-core/src/hooks/party-user-permission-authenticate.ts b/packages/server-core/src/hooks/party-user-permission-authenticate.ts index 7f32c3dc26..02269f08ea 100755 --- a/packages/server-core/src/hooks/party-user-permission-authenticate.ts +++ b/packages/server-core/src/hooks/party-user-permission-authenticate.ts @@ -2,13 +2,13 @@ import { BadRequest } from '@feathersjs/errors' import { HookContext } from '@feathersjs/feathers' import _ from 'lodash' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' // This will attach the owner ID in the contact while creating/updating list item export default () => { return async (context: HookContext): Promise => { const { params, app } = context - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params.user as UserDataType const partyId = params.query!.partyId const userId = params.query!.userId || loggedInUser.id const paramsClone = _.cloneDeep(context.params) diff --git a/packages/server-core/src/hooks/restrict-user-role.ts b/packages/server-core/src/hooks/restrict-user-role.ts index b5fd62ea87..f4cba6642b 100755 --- a/packages/server-core/src/hooks/restrict-user-role.ts +++ b/packages/server-core/src/hooks/restrict-user-role.ts @@ -1,10 +1,6 @@ import { HookContext } from '@feathersjs/feathers' -import config from '../appconfig' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' - -// Get the logged in user entity -const loggedInUserEntity: string = config.authentication.entity +import { UserDataType } from '../user/user/user.class' // This will attach the owner ID in the contact while creating/updating list item export default (userRole: string) => { @@ -12,11 +8,10 @@ export default (userRole: string) => { // console.log('restrict user role', context.params) if (context.params.isInternal) return context // Getting logged in user and attaching owner of user - const loggedInUser = extractLoggedInUserFromParams(context.params) + const loggedInUser = context.params.user as UserDataType if (loggedInUser.userRole !== userRole) { throw new Error(`Must be ${userRole} to access this function`) } - return context } } diff --git a/packages/server-core/src/hooks/send-invite.ts b/packages/server-core/src/hooks/send-invite.ts index ef9a160094..90efbd3ea0 100755 --- a/packages/server-core/src/hooks/send-invite.ts +++ b/packages/server-core/src/hooks/send-invite.ts @@ -10,13 +10,9 @@ import { UserId } from '@xrengine/common/src/interfaces/UserId' import config from '../appconfig' import logger from '../logger' import Page from '../types/PageObject' -import { - extractLoggedInUserFromParams, - getInviteLink, - sendEmail, - sendSms -} from '../user/auth-management/auth-management.utils' +import { getInviteLink, sendEmail, sendSms } from '../user/auth-management/auth-management.utils' import { UserRelationshipDataType } from '../user/user-relationship/user-relationship.class' +import { UserDataType } from '../user/user/user.class' import { Application } from './../../declarations.d' export type InviteDataType = InviteType & { targetObjectId: UserId; passcode: string } @@ -108,7 +104,7 @@ export default () => { const inviteType = result.inviteType const targetObjectId = result.targetObjectId - const authUser = extractLoggedInUserFromParams(params) + const authUser = params.user as UserDataType if (result.identityProviderType === 'email') { await generateEmail(app, result, token, inviteType, authUser.name, targetObjectId) diff --git a/packages/server-core/src/hooks/set-loggedin-user-in-body.ts b/packages/server-core/src/hooks/set-loggedin-user-in-body.ts index c6e3cfeb7a..9812e7778e 100755 --- a/packages/server-core/src/hooks/set-loggedin-user-in-body.ts +++ b/packages/server-core/src/hooks/set-loggedin-user-in-body.ts @@ -1,13 +1,13 @@ import { HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' // This will attach the owner ID in the contact while creating/updating list item export default (propertyName: string) => { return (context: HookContext): HookContext => { // console.log('\n\n\n', context) // Getting logged in user and attaching owner of user - const loggedInUser = extractLoggedInUserFromParams(context.params) + const loggedInUser = context.params.user as UserDataType if (Array.isArray(context.data)) { context.data = context.data.map((item) => { return { diff --git a/packages/server-core/src/hooks/set-loggedin-user-in-query.ts b/packages/server-core/src/hooks/set-loggedin-user-in-query.ts index 74cf50dbea..fa7f453ad2 100755 --- a/packages/server-core/src/hooks/set-loggedin-user-in-query.ts +++ b/packages/server-core/src/hooks/set-loggedin-user-in-query.ts @@ -1,13 +1,13 @@ import { HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' // TODO: Make one hook by combine this with "set-loggedin-user-in-body" // This will attach the loggedIn user id in the query property export default (propertyName: string) => { return (context: HookContext): HookContext => { // Getting logged in user and attaching owner of user - const loggedInUser = extractLoggedInUserFromParams(context.params) + const loggedInUser = context.params.user as UserDataType context.params.query = { ...context.params.query, [propertyName]: loggedInUser?.id || null diff --git a/packages/server-core/src/hooks/unset-self-party-owner.ts b/packages/server-core/src/hooks/unset-self-party-owner.ts index f1e5c34646..493741817e 100755 --- a/packages/server-core/src/hooks/unset-self-party-owner.ts +++ b/packages/server-core/src/hooks/unset-self-party-owner.ts @@ -1,13 +1,13 @@ import { HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' // This will attach the owner ID in the contact while creating/updating list item export default () => { return async (context: HookContext): Promise => { // Getting logged in user and attaching owner of user const { result } = context - const loggedInUser = extractLoggedInUserFromParams(context.params) + const loggedInUser = context.params.user as UserDataType if (loggedInUser?.id != null) { const user = await context.app.service('user').get(loggedInUser.id) if (user.partyId) { diff --git a/packages/server-core/src/hooks/verify-scope.ts b/packages/server-core/src/hooks/verify-scope.ts index f85b141660..65a288c981 100644 --- a/packages/server-core/src/hooks/verify-scope.ts +++ b/packages/server-core/src/hooks/verify-scope.ts @@ -1,15 +1,15 @@ import { HookContext } from '@feathersjs/feathers' -import { extractLoggedInUserFromParams } from '../user/auth-management/auth-management.utils' +import { UserDataType } from '../user/user/user.class' import { NotFoundException, UnauthenticatedException, UnauthorizedException } from '../util/exceptions/exception' import { Application } from './../../declarations.d' export default (currentType: string, scopeToVerify: string) => { return async (context: HookContext) => { if (context.params.isInternal) return context - const loggedInUser = extractLoggedInUserFromParams(context.params) + const loggedInUser = context.params.user as UserDataType if (!loggedInUser) throw new UnauthenticatedException('No logged in user') - const user = await context.app.service('user').get(loggedInUser.id) + const user = await context.app.service('user').get(loggedInUser.id!) if (user.userRole === 'admin') return context const scopes = await context.app.service('scope').Model.findAll({ where: { diff --git a/packages/server-core/src/networking/instance/instance.class.ts b/packages/server-core/src/networking/instance/instance.class.ts index ec0be5e5e2..d0c7196915 100755 --- a/packages/server-core/src/networking/instance/instance.class.ts +++ b/packages/server-core/src/networking/instance/instance.class.ts @@ -34,7 +34,7 @@ export class Instance extends Service { if (action === 'admin') { //TODO: uncomment here - // const loggedInUser = extractLoggedInUserFromParams(params) + // const loggedInUser = params.user as UserDataType // const user = await super.get(loggedInUser.userId); // console.log(user); // if (user.userRole !== 'admin') throw new Forbidden ('Must be system admin to execute this action'); diff --git a/packages/server-core/src/setting/authentication-setting/authentication.class.ts b/packages/server-core/src/setting/authentication-setting/authentication.class.ts index ec21d47c1f..ec20042cc2 100644 --- a/packages/server-core/src/setting/authentication-setting/authentication.class.ts +++ b/packages/server-core/src/setting/authentication-setting/authentication.class.ts @@ -5,7 +5,7 @@ import { AdminAuthSetting as AdminAuthSettingInterface } from '@xrengine/common/ import { Application } from '../../../declarations' import config from '../../appconfig' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' +import { UserDataType } from '../../user/user/user.class' export type AdminAuthSettingDataType = AdminAuthSettingInterface @@ -19,7 +19,7 @@ export class Authentication extends Service { async find(params?: Params): Promise> { const auth = (await super.find()) as any - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params!.user as UserDataType const data = auth.data.map((el) => { let oauth = JSON.parse(el.oauth) let authStrategies = JSON.parse(el.authStrategies) diff --git a/packages/server-core/src/social/channel/channel.class.ts b/packages/server-core/src/social/channel/channel.class.ts index c067dbdd61..581795bed3 100755 --- a/packages/server-core/src/social/channel/channel.class.ts +++ b/packages/server-core/src/social/channel/channel.class.ts @@ -7,7 +7,7 @@ import { Channel as ChannelInterface } from '@xrengine/common/src/interfaces/Cha import { Application } from '../../../declarations' import logger from '../../logger' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' +import { UserDataType } from '../../user/user/user.class' export type ChannelDataType = ChannelInterface @@ -32,7 +32,7 @@ export class Channel extends Service { const query = params.query! const skip = query?.skip || 0 const limit = query?.limit || 10 - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params!.user as UserDataType const userId = loggedInUser.id const Model = (this.app.service('channel') as any).Model try { diff --git a/packages/server-core/src/social/group/group.class.ts b/packages/server-core/src/social/group/group.class.ts index 61bc3b6961..7498a3517f 100755 --- a/packages/server-core/src/social/group/group.class.ts +++ b/packages/server-core/src/social/group/group.class.ts @@ -5,7 +5,7 @@ import { Op } from 'sequelize' import { Group as GroupInterface } from '@xrengine/common/src/interfaces/Group' import { Application } from '../../../declarations' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' +import { UserDataType } from '../../user/user/user.class' export type GroupDataType = GroupInterface /** @@ -30,7 +30,7 @@ export class Group extends Service { */ async find(params?: Params): Promise> { - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params!.user as UserDataType const skip = params?.query?.$skip ? params.query.$skip : 0 const limit = params?.query?.$limit ? params.query.$limit : 10 const search = params?.query?.search diff --git a/packages/server-core/src/social/invite/invite.class.ts b/packages/server-core/src/social/invite/invite.class.ts index e57138aafa..5d592873b8 100755 --- a/packages/server-core/src/social/invite/invite.class.ts +++ b/packages/server-core/src/social/invite/invite.class.ts @@ -5,7 +5,7 @@ import { Invite as InviteType } from '@xrengine/common/src/interfaces/Invite' import { UserId } from '@xrengine/common/src/interfaces/UserId' import { Application } from '../../../declarations' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' +import { UserDataType } from '../../user/user/user.class' export type InviteDataType = InviteType & { targetObjectId: UserId; passcode: string } @@ -100,7 +100,7 @@ export class Invite extends Service { async remove(id: string, params?: Params): Promise { const invite = await this.app.service('invite').get(id) if (invite.inviteType === 'friend' && invite.inviteeId != null && !params?.preventUserRelationshipRemoval) { - const selfUser = extractLoggedInUserFromParams(params) + const selfUser = params!.user as UserDataType const relatedUserId = invite.userId === selfUser.id ? invite.inviteeId : invite.userId await this.app.service('user-relationship').remove(relatedUserId, params) } diff --git a/packages/server-core/src/social/location-ban/location-ban.hooks.ts b/packages/server-core/src/social/location-ban/location-ban.hooks.ts index 2756cc919b..f9f3af0183 100755 --- a/packages/server-core/src/social/location-ban/location-ban.hooks.ts +++ b/packages/server-core/src/social/location-ban/location-ban.hooks.ts @@ -3,7 +3,7 @@ import { HookContext } from '@feathersjs/feathers' import { disallow } from 'feathers-hooks-common' import authenticate from '../../hooks/authenticate' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' +import { UserDataType } from '../../user/user/user.class' export default { before: { @@ -12,8 +12,8 @@ export default { get: [], create: [ async (context): Promise => { - const { app, data } = context - const loggedInUser = extractLoggedInUserFromParams(context.params) + const { app, data, params } = context + const loggedInUser = params.user as UserDataType const locationAdmins = await app.service('location-admin').find({ query: { locationId: data.locationId, diff --git a/packages/server-core/src/social/location/location.class.ts b/packages/server-core/src/social/location/location.class.ts index 815dca4e4a..940b65a274 100755 --- a/packages/server-core/src/social/location/location.class.ts +++ b/packages/server-core/src/social/location/location.class.ts @@ -6,7 +6,7 @@ import slugify from 'slugify' import { Location as LocationType } from '@xrengine/common/src/interfaces/Location' import { Application } from '../../../declarations' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' +import { UserDataType } from '../../user/user/user.class' export type LocationDataType = LocationType @@ -169,7 +169,7 @@ export class Location extends Service { data: locationResult.rows } } else if (adminnedLocations) { - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params!.user as UserDataType const include = [ { model: (this.app.service('location-settings') as any).Model, @@ -236,7 +236,7 @@ export class Location extends Service { try { // @ts-ignore let { location_settings, ...locationData } = data - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params!.user as UserDataType locationData.slugifiedName = slugify(locationData.name, { lower: true }) if (locationData.isLobby) await this.makeLobby(t, params) @@ -346,7 +346,7 @@ export class Location extends Service { async remove(id: string, params?: Params): Promise { if (id != null) { - const selfUser = extractLoggedInUserFromParams(params) + const selfUser = params!.user as UserDataType const location = await this.app.service('location').get(id) if (location.locationSettingsId != null) await this.app.service('location-settings').remove(location.locationSettingsId) @@ -365,7 +365,7 @@ export class Location extends Service { } async makeLobby(t, params?: Params): Promise { - const selfUser = extractLoggedInUserFromParams(params) + const selfUser = params!.user as UserDataType if (!selfUser || selfUser.userRole !== 'admin') throw new Error('Only Admin can set Lobby') diff --git a/packages/server-core/src/social/message/message.class.ts b/packages/server-core/src/social/message/message.class.ts index db91c8b9c8..c61f5eb921 100755 --- a/packages/server-core/src/social/message/message.class.ts +++ b/packages/server-core/src/social/message/message.class.ts @@ -6,7 +6,7 @@ import { Op } from 'sequelize' import { Message as MessageInterface } from '@xrengine/common/src/interfaces/Message' import { Application } from '../../../declarations' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' +import { UserDataType } from '../../user/user/user.class' export type MessageDataType = MessageInterface @@ -28,7 +28,7 @@ export class Message extends Service { async create(data: any, params?: Params): Promise { let channel, channelId let userIdList: any[] = [] - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params!.user as UserDataType const userId = loggedInUser?.id const targetObjectId = data.targetObjectId const targetObjectType = data.targetObjectType diff --git a/packages/server-core/src/social/message/message.hooks.ts b/packages/server-core/src/social/message/message.hooks.ts index b6680fae6b..0de5484893 100755 --- a/packages/server-core/src/social/message/message.hooks.ts +++ b/packages/server-core/src/social/message/message.hooks.ts @@ -5,7 +5,6 @@ import removeMessageStatuses from '@xrengine/server-core/src/hooks/remove-messag import authenticate from '../../hooks/authenticate' -// import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' // Don't remove this comment. It's needed to format import lines nicely. export default { diff --git a/packages/server-core/src/social/party-user/party-user.hooks.ts b/packages/server-core/src/social/party-user/party-user.hooks.ts index 7603586459..752370e4c6 100755 --- a/packages/server-core/src/social/party-user/party-user.hooks.ts +++ b/packages/server-core/src/social/party-user/party-user.hooks.ts @@ -8,7 +8,7 @@ import unsetSelfPartyOwner from '@xrengine/server-core/src/hooks/unset-self-part import authenticate from '../../hooks/authenticate' import logger from '../../logger' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' +import { UserDataType } from '../../user/user/user.class' // Don't remove this comment. It's needed to format import lines nicely. @@ -21,8 +21,8 @@ export default { async (context: HookContext): Promise => { try { const { app, params, data } = context - const loggedInUser = extractLoggedInUserFromParams(params) - const user = await app.service('user').get(loggedInUser.id) + const loggedInUser = params!.user as UserDataType + const user = await app.service('user').get(loggedInUser.id!) const partyUserResult = await app.service('party-user').find({ query: { userId: loggedInUser.id diff --git a/packages/server-core/src/social/party/party.class.ts b/packages/server-core/src/social/party/party.class.ts index 4511025807..bbb85197ca 100755 --- a/packages/server-core/src/social/party/party.class.ts +++ b/packages/server-core/src/social/party/party.class.ts @@ -7,7 +7,7 @@ import { Party as PartyDataType } from '@xrengine/common/src/interfaces/Party' // import { Params, Id, NullableId } from '@feathersjs/feathers' import { Application } from '../../../declarations' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' +import { UserDataType } from '../../user/user/user.class' // import { Forbidden } from '@feathersjs/errors' @@ -83,7 +83,7 @@ export class Party extends Service { */ async get(id: string, params?: Params): Promise { if (id == null) { - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params!.user as UserDataType const partyUserResult = await this.app.service('party-user').find({ query: { userId: loggedInUser.id diff --git a/packages/server-core/src/social/party/party.hooks.ts b/packages/server-core/src/social/party/party.hooks.ts index d3e77fa26d..6d0d42b55f 100755 --- a/packages/server-core/src/social/party/party.hooks.ts +++ b/packages/server-core/src/social/party/party.hooks.ts @@ -8,7 +8,7 @@ import removePartyUsers from '@xrengine/server-core/src/hooks/remove-party-users import addAssociations from '../../hooks/add-associations' import authenticate from '../../hooks/authenticate' import restrictUserRole from '../../hooks/restrict-user-role' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' +import { UserDataType } from '../../user/user/user.class' // Don't remove this comment. It's needed to format import lines nicely. @@ -34,7 +34,7 @@ export default { get: [], create: [ async (context): Promise => { - const loggedInUser = extractLoggedInUserFromParams(context.params) + const loggedInUser = context.params.user as UserDataType const currentPartyUser = await context.app.service('party-user').find({ query: { userId: loggedInUser.id diff --git a/packages/server-core/src/user/auth-management/auth-management.utils.ts b/packages/server-core/src/user/auth-management/auth-management.utils.ts index 8595b3c30d..adfe9d94a2 100755 --- a/packages/server-core/src/user/auth-management/auth-management.utils.ts +++ b/packages/server-core/src/user/auth-management/auth-management.utils.ts @@ -67,14 +67,3 @@ export const sendSms = async (app: Application, sms: any): Promise => { .then(() => console.log('Sent SMS')) .catch((err: any) => console.log('Error sending SMS', err)) } - -/** - * This method will extract the loggedIn User from params - * - * @param params - * @returns extracted user - * @author Vyacheslav Solovjov - */ -export const extractLoggedInUserFromParams = (params?: Params): any => { - return params?.user -} diff --git a/packages/server-core/src/user/identity-provider/identity-provider.class.ts b/packages/server-core/src/user/identity-provider/identity-provider.class.ts index 9af59c093a..29dc8aec77 100755 --- a/packages/server-core/src/user/identity-provider/identity-provider.class.ts +++ b/packages/server-core/src/user/identity-provider/identity-provider.class.ts @@ -13,7 +13,7 @@ import config from '../../appconfig' import { scopeTypeSeed } from '../../scope/scope-type/scope-type.seed' import Paginated from '../../types/PageObject' import getFreeInviteCode from '../../util/get-free-invite-code' -import { extractLoggedInUserFromParams } from '../auth-management/auth-management.utils' +import { UserDataType } from '../user/user.class' /** * A class for identity-provider service @@ -236,7 +236,7 @@ export class IdentityProvider extends Service } async find(params?: Params): Promise> { - const loggedInUser = extractLoggedInUserFromParams(params!) + const loggedInUser = params!.user as UserDataType if (params!.provider) params!.query!.userId = loggedInUser.id return super.find(params) } diff --git a/packages/server-core/src/user/user-api-key/user-api-key.class.ts b/packages/server-core/src/user/user-api-key/user-api-key.class.ts index 13b621eb98..87b177e7b3 100755 --- a/packages/server-core/src/user/user-api-key/user-api-key.class.ts +++ b/packages/server-core/src/user/user-api-key/user-api-key.class.ts @@ -5,7 +5,7 @@ import { v1 } from 'uuid' import { UserApiKeyInterface } from '@xrengine/common/src/dbmodels/UserApiKey' import { Application } from '../../../declarations' -import { extractLoggedInUserFromParams } from '../auth-management/auth-management.utils' +import { UserDataType } from '../user/user.class' export type UserApiKeyDataType = UserApiKeyInterface & { userId: string } /** @@ -22,7 +22,7 @@ export class UserApiKey extends Service { } async patch(id: string | null, data: any, params: Params = {}): Promise { - const loggedInUser = await extractLoggedInUserFromParams(params) + const loggedInUser = params.user as UserDataType if (loggedInUser.userRole === 'admin' && id != null && params) return super.patch(id, { ...data }) const userApiKey = await this.app.service('user-api-key').Model.findOne({ where: { diff --git a/packages/server-core/src/user/user/user.class.ts b/packages/server-core/src/user/user/user.class.ts index 81173c3af6..66388e280f 100755 --- a/packages/server-core/src/user/user/user.class.ts +++ b/packages/server-core/src/user/user/user.class.ts @@ -7,7 +7,6 @@ import { Op } from 'sequelize' import { User as UserInterface } from '@xrengine/common/src/interfaces/User' import { Application } from '../../../declarations' -import { extractLoggedInUserFromParams } from '../../user/auth-management/auth-management.utils' export type UserDataType = UserInterface /** @@ -40,9 +39,11 @@ export class User extends Service { delete query.search + const loggedInUser = params!.user as UserDataType + if (action === 'friends') { delete params.query.action - const loggedInUser = extractLoggedInUserFromParams(params) + const loggedInUser = params!.user as UserDataType const userResult = await (this.app.service('user') as any).Model.findAndCountAll({ offset: skip, limit: limit, @@ -64,19 +65,16 @@ export class User extends Service { return super.find(params) } else if (action === 'layer-users') { delete params.query.action - const loggedInUser = extractLoggedInUserFromParams(params) params.query.instanceId = params.query.instanceId || loggedInUser.instanceId || 'intentionalBadId' return super.find(params) } else if (action === 'channel-users') { delete params.query.action - const loggedInUser = extractLoggedInUserFromParams(params) params.query.channelInstanceId = params.query.channelInstanceId || loggedInUser.channelInstanceId || 'intentionalBadId' return super.find(params) } else if (action === 'admin') { delete params.query.action delete params.query.search - const loggedInUser = extractLoggedInUserFromParams(params) if (!params.isInternal && loggedInUser.userRole !== 'admin') throw new Forbidden('Must be system admin to execute this action') @@ -115,7 +113,6 @@ export class User extends Service { delete params.query.action return super.find(params) } else { - const loggedInUser = extractLoggedInUserFromParams(params) if (loggedInUser?.userRole !== 'admin' && !params.isInternal) throw new Forbidden('Must be system admin to execute this action') return await super.find(params) diff --git a/packages/server-core/src/user/user/user.hooks.ts b/packages/server-core/src/user/user/user.hooks.ts index ba392c114b..235546c238 100755 --- a/packages/server-core/src/user/user/user.hooks.ts +++ b/packages/server-core/src/user/user/user.hooks.ts @@ -8,13 +8,13 @@ import authenticate from '../../hooks/authenticate' import restrictUserRole from '../../hooks/restrict-user-role' import logger from '../../logger' import getFreeInviteCode from '../../util/get-free-invite-code' -import { extractLoggedInUserFromParams } from '../auth-management/auth-management.utils' +import { UserDataType } from './user.class' const restrictUserPatch = (context: HookContext) => { if (context.params.isInternal) return context // allow admins for all patch actions - const loggedInUser = extractLoggedInUserFromParams(context.params) + const loggedInUser = context.params.user as UserDataType if (loggedInUser.userRole === 'admin') return context // only allow a user to patch it's own data