(init: RequestInit = {}, token: string = DEFAULT_TOKEN)
| 60 | * need to send a wrong/no token can still do so explicitly. |
| 61 | */ |
| 62 | export function withAuth(init: RequestInit = {}, token: string = DEFAULT_TOKEN): RequestInit { |
| 63 | const headers = new Headers(init.headers); |
| 64 | if (!headers.has('Authorization')) { |
| 65 | headers.set('Authorization', `Bearer ${token}`); |
| 66 | } |
| 67 | return { ...init, headers }; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * WS subprotocol prefix that carries the bearer token during the upgrade. |