The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/app/api/server/helpers/getLoggedInUser.ts

14 lines
612 B

import { Accounts } from 'meteor/accounts-base';
import { Users } from '@rocket.chat/models';
import type { IUser } from '@rocket.chat/core-typings';
import type { Request } from 'express';
export async function getLoggedInUser(request: Request): Promise<Pick<IUser, '_id' | 'username'> | null> {
const token = request.headers['x-auth-token'];
const userId = request.headers['x-user-id'];
if (!token || !userId || typeof token !== 'string' || typeof userId !== 'string') {
return null;
}
return Users.findOneByIdAndLoginToken(userId, Accounts._hashLoginToken(token), { projection: { username: 1 } });
}