Skip to content

Commit

Permalink
[DEV-3653] Fixed auth
Browse files Browse the repository at this point in the history
  • Loading branch information
davidleomay committed Feb 18, 2025
1 parent 69c6b89 commit 1b7a0f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
46 changes: 23 additions & 23 deletions packages/react/src/hooks/api.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface CallConfig {
noJson?: boolean;
responseType?: ResponseType;
specialHandling?: SpecialHandling;
token?: string;
token?: string | false;
}

interface SpecialHandling {
Expand Down Expand Up @@ -49,31 +49,31 @@ export function useApi(): ApiInterface {
const version = config.version ?? defaultVersion;
const baseUrl = `${url}/${version}`;
const responseType = config.responseType ?? ResponseType.JSON;
const token = config.token === false ? undefined : config.token ?? authenticationToken;

return fetch(
`${baseUrl}/${config.url}`,
buildInit(config.method, config.token ?? authenticationToken, config.data, config.noJson),
).then((response) => {
if (response.status === config.specialHandling?.statusCode) {
config.specialHandling?.action?.();
}
if (response.ok) {
switch (responseType) {
case ResponseType.JSON:
return response.json().catch(() => undefined) as Promise<T>;
case ResponseType.TEXT:
return response.text() as Promise<T>;
case ResponseType.BLOB:
return response.blob() as Promise<T>;
default:
throw new Error('Unknown response type');
return fetch(`${baseUrl}/${config.url}`, buildInit(config.method, token, config.data, config.noJson)).then(
(response) => {
if (response.status === config.specialHandling?.statusCode) {
config.specialHandling?.action?.();
}
if (response.ok) {
switch (responseType) {
case ResponseType.JSON:
return response.json().catch(() => undefined) as Promise<T>;
case ResponseType.TEXT:
return response.text() as Promise<T>;
case ResponseType.BLOB:
return response.blob() as Promise<T>;
default:
throw new Error('Unknown response type');
}
}
}

return response.json().then((body) => {
throw body;
});
});
return response.json().then((body) => {
throw body;
});
},
);
}

function buildInit(
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/hooks/auth.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function useAuth(): AuthInterface {
usedRef?: string,
): Promise<SignIn> {
const data = getParams(address, signature, key, specialCode, wallet, usedRef);
return call({ url: AuthUrl.auth, method: 'POST', data });
return call({ url: AuthUrl.auth, method: 'POST', data, token: false });
}

async function signIn(address: string, signature: string, key?: string, specialCode?: string): Promise<SignIn> {
Expand Down

0 comments on commit 1b7a0f1

Please sign in to comment.