@@ -2,7 +2,7 @@ import { createOk, mapForResult, type Result } from "option-t/plain_result";
22import { getProfile } from "./profile.ts" ;
33import type { HTTPError } from "./responseIntoResult.ts" ;
44import type { AbortError , NetworkError } from "./robustFetch.ts" ;
5- import type { BaseOptions } from "./options.ts" ;
5+ import type { ExtendedOptions } from "./options.ts" ;
66
77/** HTTP headerのCookieに入れる文字列を作る
88 *
@@ -15,13 +15,12 @@ export const cookie = (sid: string): string => `connect.sid=${sid}`;
1515 * @param init 認証情報など
1616 */
1717export const getCSRFToken = async (
18- init ?: BaseOptions ,
19- ) : Promise < Result < string , NetworkError | AbortError | HTTPError > > =>
18+ init ?: ExtendedOptions ,
19+ ) : Promise < Result < string , NetworkError | AbortError | HTTPError > > => {
2020 // deno-lint-ignore no-explicit-any
21- ( globalThis as any ) . _csrf
22- // deno-lint-ignore no-explicit-any
23- ? createOk ( ( globalThis as any ) . _csrf )
24- : mapForResult (
25- await getProfile ( init ) ,
26- ( user ) => user . csrfToken ,
27- ) ;
21+ const csrf = init ?. csrf ?? ( globalThis as any ) . _csrf ;
22+ return csrf ? createOk ( csrf ) : mapForResult (
23+ await getProfile ( init ) ,
24+ ( user ) => user . csrfToken ,
25+ ) ;
26+ } ;
0 commit comments