diff --git a/packages/server/src/api/controllers/user.ts b/packages/server/src/api/controllers/user.ts index bdbb1c7f93..8af7619634 100644 --- a/packages/server/src/api/controllers/user.ts +++ b/packages/server/src/api/controllers/user.ts @@ -28,9 +28,10 @@ export async function syncUser(ctx: Ctx) { } } - let previousApps = isUser(previousUser) - ? Object.keys(previousUser.roles).map(appId => appId) - : [] + let previousApps = + previousUser && isUser(previousUser) + ? Object.keys(previousUser.roles).map(appId => appId) + : [] const roles = deleting ? {} : user.roles // remove props which aren't useful to metadata diff --git a/packages/types/src/documents/global/user.ts b/packages/types/src/documents/global/user.ts index 5787318680..91543a6368 100644 --- a/packages/types/src/documents/global/user.ts +++ b/packages/types/src/documents/global/user.ts @@ -70,6 +70,6 @@ export interface AdminUser extends User { } } -export function isUser(user: any): user is User { +export function isUser(user: object): user is User { return !!(user as User).roles }