Skip to content

Commit ae492c7

Browse files
committed
feat: search for embedded session key and set as token, if missing
1 parent 097d0e2 commit ae492c7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/templates/core/fetch/getHeaders.hbs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
2-
const [token, username, password, additionalHeaders] = await Promise.all([
2+
let [token, username, password, additionalHeaders] = await Promise.all([
33
resolve(options, config.TOKEN),
44
resolve(options, config.USERNAME),
55
resolve(options, config.PASSWORD),
66
resolve(options, config.HEADERS),
77
]);
88

9+
if (!isStringWithValue(token)) {
10+
const SESSION_KEY = '_anyroad_embedded_session_key';
11+
token = document?.cookie?.split('; ').find(row => row.startsWith(`${SESSION_KEY}=`))?.split('=')[1];
12+
}
13+
914
const headers = Object.entries({
1015
Accept: 'application/json',
1116
...additionalHeaders,

0 commit comments

Comments
 (0)