feat(reddit): provide user-agent header
This commit is contained in:
@@ -1,10 +1,22 @@
|
|||||||
import { TBeforeRequest } from '@automatisch/types';
|
import { TBeforeRequest } from '@automatisch/types';
|
||||||
|
import appConfig from '../../../config/app';
|
||||||
|
|
||||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||||
|
const screenName = $.auth.data?.screenName as string;
|
||||||
if ($.auth.data?.accessToken) {
|
if ($.auth.data?.accessToken) {
|
||||||
requestConfig.headers.Authorization = `${$.auth.data.tokenType} ${$.auth.data.accessToken}`;
|
requestConfig.headers.Authorization = `${$.auth.data.tokenType} ${$.auth.data.accessToken}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (screenName) {
|
||||||
|
requestConfig.headers[
|
||||||
|
'User-Agent'
|
||||||
|
] = `web:automatisch:${appConfig.version} (by /u/${screenName})`;
|
||||||
|
} else {
|
||||||
|
requestConfig.headers[
|
||||||
|
'User-Agent'
|
||||||
|
] = `web:automatisch:${appConfig.version}`;
|
||||||
|
}
|
||||||
|
|
||||||
return requestConfig;
|
return requestConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user