Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const context = (moduleName: string) => async (
{ req }: AccountsRequest,
_: any,
{ injector }: ModuleSessionInfo
) => {
if (!req) {
return {
ip: '',
userAgent: '',
};
}
const config: AccountsModuleConfig = injector.get(ModuleConfig(moduleName));
const headerName = config.headerName || 'Authorization';
let authToken = (req.headers[headerName] || req.headers[headerName.toLowerCase()]) as string;
authToken = authToken && authToken.replace('Bearer ', '');
let user;
if (authToken && !config.excludeAddUserInContext) {
try {
user = await config.accountsServer.resumeSession(authToken);
} catch (error) {
// Empty catch
}
}
let userAgent: string = (req.headers['user-agent'] as string) || '';
if (req.headers['x-ucbrowser-ua']) {
// special case of UC Browser
constructor(
@inject(ModuleConfig('info')) private config: any,
@inject(CommunicationBridge)
private communicationBridge: CommunicationBridge,
@inject(AppInfo) private app: AppInfo,
) {}