- API 클라이언트·토큰 갱신·순수 함수를 shared/ (@nalssigak/shared) 로 옮김 - 토큰 저장소·API 주소는 configureApi 로 플랫폼에서 넣는다 (웹 localStorage) - 루트 package.json 에 frontend·mobile·shared workspaces, lock 파일 하나로 - 웹 Docker 빌드 대상을 저장소 루트로 (compose context ., 루트 .dockerignore)
49 lines
1.0 KiB
TypeScript
49 lines
1.0 KiB
TypeScript
// This file is auto-generated by @hey-api/openapi-ts
|
|
|
|
export type AuthToken = string | undefined;
|
|
|
|
export interface Auth {
|
|
/**
|
|
* Which part of the request do we use to send the auth?
|
|
*
|
|
* @default 'header'
|
|
*/
|
|
in?: 'header' | 'query' | 'cookie';
|
|
/**
|
|
* A unique identifier for the security scheme.
|
|
*
|
|
* Defined only when there are multiple security schemes whose `Auth`
|
|
* shape would otherwise be identical.
|
|
*/
|
|
key?: string;
|
|
/**
|
|
* Header or query parameter name.
|
|
*
|
|
* @default 'Authorization'
|
|
*/
|
|
name?: string;
|
|
scheme?: 'basic' | 'bearer';
|
|
type: 'apiKey' | 'http';
|
|
}
|
|
|
|
export const getAuthToken = async (
|
|
auth: Auth,
|
|
callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
|
|
): Promise<string | undefined> => {
|
|
const token = typeof callback === 'function' ? await callback(auth) : callback;
|
|
|
|
if (!token) {
|
|
return;
|
|
}
|
|
|
|
if (auth.scheme === 'bearer') {
|
|
return `Bearer ${token}`;
|
|
}
|
|
|
|
if (auth.scheme === 'basic') {
|
|
return `Basic ${btoa(token)}`;
|
|
}
|
|
|
|
return token;
|
|
};
|