Skip to content

Commit d26fe68

Browse files
feat: addition of cookies and basic auth - 9
1 parent 58e5453 commit d26fe68

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/lib/ctx.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Context, Env, WebConfig, MobileConfig } from '../types.js'
1+
import { Context, Env, WebConfig, MobileConfig, basicAuth } from '../types.js'
22
import constants from './constants.js'
33
import { version } from '../../package.json'
44
import { validateConfig } from './schemaValidation.js'
@@ -11,6 +11,7 @@ export default (options: Record<string, string>): Context => {
1111
let env: Env = getEnv();
1212
let webConfig: WebConfig;
1313
let mobileConfig: MobileConfig;
14+
let basicAuthObj: basicAuth
1415
let config = constants.DEFAULT_CONFIG;
1516
let port: number;
1617
let resolutionOff: boolean;
@@ -57,6 +58,12 @@ export default (options: Record<string, string>): Context => {
5758
}
5859
}
5960

61+
console.dir(basicAuthObj)
62+
console.log("**************")
63+
if (config.basicAuthorization){
64+
basicAuthObj = config.basicAuthorization
65+
}
66+
6067
return {
6168
env: env,
6269
log: logger,
@@ -70,7 +77,7 @@ export default (options: Record<string, string>): Context => {
7077
cliEnableJavaScript: config.cliEnableJavaScript || true,
7178
scrollTime: config.scrollTime || constants.DEFAULT_SCROLL_TIME,
7279
allowedHostnames: config.allowedHostnames || [],
73-
basicAuthorization: config.basicAuthorization || {username: '', password:''}
80+
basicAuthorization: basicAuthObj
7481
},
7582
uploadFilePath: '',
7683
webStaticConfig: [],

src/lib/processSnapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
130130
let requestOptions: Record<string, any> = {
131131
timeout: REQUEST_TIMEOUT
132132
}
133-
if (requestUrl === snapshot.url && ctx.config.basicAuthorization.username !== '' ) {
134-
ctx.log.debug(`Adding basic authorization to the headers for root url`);
133+
if (requestUrl === snapshot.url && ctx.config.basicAuthorization ) {
134+
ctx.log.debug(`Adding basic authorization to the headers for root url with username: ${ctx.config.basicAuthorization.username}`);
135135
let token = Buffer.from(`${ctx.config.basicAuthorization.username}:${ctx.config.basicAuthorization.password}`).toString('base64');
136136
requestOptions.headers = {
137137
...request.headers(),

src/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface Context {
2323
cliEnableJavaScript: boolean;
2424
scrollTime: number;
2525
allowedHostnames: Array<string>;
26-
basicAuthorization: {username: string, password: string}
26+
basicAuthorization: basicAuth | undefined
2727
};
2828
uploadFilePath: string;
2929
webStaticConfig: WebStaticConfig;
@@ -142,3 +142,8 @@ export type FigmaDesignConfig = {
142142
depth: number;
143143
figma_config: FigmaConfigItem[];
144144
};
145+
146+
export interface basicAuth {
147+
username: string;
148+
password: string;
149+
}

0 commit comments

Comments
 (0)