Skip to content

Commit

Permalink
Merge pull request #277 from node-real/feat/offchain-auth-check
Browse files Browse the repository at this point in the history
feat(dcellar-web-ui): add bad signature check
  • Loading branch information
aiden-cao authored Nov 17, 2023
2 parents 3add564 + 2179579 commit fa61f03
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ export const GlobalTasks = memo<GlobalTasksProps>(function GlobalTasks() {
.catch(async (e: Response | any) => {
console.log('upload error', e);
const { message } = await parseErrorXml(e);
const authExpired =
message?.includes('invalid signature') ||
message?.includes('user public key is expired');
const authExpired = [
'bad signature',
'invalid signature',
'user public key is expired',
].includes(message || '');
if (authExpired) {
setOpenAuthModal();
setAuthModal(true);
Expand Down
4 changes: 3 additions & 1 deletion apps/dcellar-web-ui/src/facade/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const E_FULL_OBJECT_NAME_TOO_LONG = 'FULL_OBJECT_NAME_TOO_LONG';
export const E_ACCOUNT_BALANCE_NOT_ENOUGH = 'ACCOUNT_BALANCE_NOT_ENOUGH';
export const E_NO_PERMISSION = 'NO_PERMISSION';
export const E_SP_STORAGE_PRICE_FAILED = 'SP_STORAGE_PRICE_FAILED';

export declare class BroadcastTxError extends Error {
readonly code: number;
readonly codespace: string;
Expand Down Expand Up @@ -75,9 +76,10 @@ export const createTxFault = (e: any): ErrorResponse => {
'Get create bucket approval error.',
'user public key is expired',
'invalid signature',
'bad signature',
].includes(message)) ||
((e as any).statusCode === 400 &&
['user public key is expired', 'invalid signature'].includes(message))
['user public key is expired', 'invalid signature', 'bad signature'].includes(message))
) {
return [null, E_OFF_CHAIN_AUTH];
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dcellar-web-ui/src/facade/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const getCanObjectAccess = async (
seedString,
};
const [info, quota, error] = await getObjectInfoAndBucketQuota(params);
if (error === 'invalid signature' || error === 'user public key is expired') {
if (['bad signature', 'invalid signature', 'user public key is expired'].includes(error || '')) {
return [false, E_OFF_CHAIN_AUTH];
}
if (!info) return [false, E_NOT_FOUND];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ export const ObjectList = memo<ObjectListProps>(function ObjectList() {
address: loginAccount,
};
const [objectInfo, quotaData, error] = await getObjectInfoAndBucketQuota(gParams);
if (error === 'invalid signature' || error === 'user public key is expired') {
if (
['bad signature', 'invalid signature', 'user public key is expired'].includes(error || '')
) {
return onError(E_OFF_CHAIN_AUTH);
}
if (!quotaData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export const ObjectNameColumn = memo<ObjectNameColumnProps>(function NameItem({
address: loginAccount,
};
const [objectInfo, quotaData, error] = await getObjectInfoAndBucketQuota(gParams);
if (error === 'invalid signature' || error === 'user public key is expired') {
if (
['bad signature', 'invalid signature', 'user public key is expired'].includes(error || '')
) {
return onError(E_OFF_CHAIN_AUTH);
}
if (objectInfo === null) {
Expand Down
4 changes: 3 additions & 1 deletion apps/dcellar-web-ui/src/pages/share/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ const SharePage: NextPage<PageProps> = (props) => {
}

const [objectInfo, quotaData, error] = await getObjectInfoAndBucketQuota(params);
if (error === 'invalid signature' || error === 'user public key is expired') {
if (
['bad signature', 'invalid signature', 'user public key is expired'].includes(error || '')
) {
logout(true);
}
setObjectInfo(objectInfo);
Expand Down
4 changes: 3 additions & 1 deletion apps/dcellar-web-ui/src/store/slices/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ export const setupBucketQuota =
});
dispatch(setQuotaLoading(false));
if (quota === null) {
if (['invalid signature', 'user public key is expired'].includes(error)) {
if (
['bad signature', 'invalid signature', 'user public key is expired'].includes(error || '')
) {
dispatch(setAuthModalOpen([true, { action: 'quota', params: { bucketName } }]));
} else {
console.error({ description: error || 'Get bucket read quota error' });
Expand Down

0 comments on commit fa61f03

Please sign in to comment.