Skip to content

Commit

Permalink
improve type select. (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin authored Nov 22, 2023
1 parent 9c19d20 commit a631a4c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export interface FetchInit extends Omit<RequestInit, "integrity" | "window">{
query?: URLSearchParams;
secret?: {
key: string;
id?: undefined;
pw?: undefined;
} | {
key?: undefined;
id: string;
pw: string;
};
Expand Down Expand Up @@ -50,14 +53,12 @@ export async function fetchExtend<T extends keyof ResponseType>(path:string, typ
u.searchParams.set(k, v);
}

if(option?.secret){
if("key" in option.secret){
h.set("Authorization", `Bearer ${option.secret.key}`);
}
else{
u.username = option.secret.id;
u.password = option.secret.pw;
}
if(option?.secret?.key){
h.set("Authorization", `Bearer ${option.secret.key}`);
}
else if(option?.secret?.id){
u.username = option.secret.id;
u.password = option.secret.pw;
}

const response = await fetch(u.href, {
Expand Down

0 comments on commit a631a4c

Please sign in to comment.