Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix JWT permissions not signed #493

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class AppHeader extends Vue {
@walletModule.Action('disconnectWallet') disconnectWallet!: () => void
@walletModule.Action('openConnectWalletModal') openConnectWalletModal!: (params: { language: string, fullPath?: string }) => Promise<any>
@walletModule.Action('initWallet') initWallet!: (params: { method: any, accounts: any, offlineSigner?: any }) => Promise<any>
@walletModule.Action('signMessageMemo') signMessageMemo!: (action: string, permissions?: string[]) => Promise<any>
@walletModule.Action('signMessageMemo') signMessageMemo!: (params: { action: string; permissions: string[] }) => Promise<any>
@walletModule.Getter('getWalletAddress') currentAddress!: string
@walletModule.Getter('getSigner') signer!: any
@bookApiModule.Getter('getSessionWallet') sessionWallet!: string
Expand Down Expand Up @@ -230,7 +230,10 @@ export default class AppHeader extends Vue {
if (!this.currentAddress || !this.signer) {
throw new Error('FAILED_TO_CONNECT_WALLET')
}
const signature = await this.signMessageMemo('authorize', SIGN_AUTHORIZATION_PERMISSIONS)
const signature = await this.signMessageMemo({
action: 'authorize',
permissions: SIGN_AUTHORIZATION_PERMISSIONS,
});
if (!signature) {
throw new Error('SIGNING_REJECTED')
}
Expand Down
7 changes: 5 additions & 2 deletions layouts/wallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class WalletLayout extends Vue {
@walletModule.Action('disconnectWallet') disconnectWallet!: () => void
@walletModule.Action('openConnectWalletModal') openConnectWalletModal!: (params: { language: string, fullPath?: string }) => Promise<any>
@walletModule.Action('initWallet') initWallet!: (params: { method: any, accounts: any, offlineSigner?: any }) => Promise<any>
@walletModule.Action('signMessageMemo') signMessageMemo!: (action: string, permissions?: string[]) => Promise<any>
@walletModule.Action('signMessageMemo') signMessageMemo!: (params: { action: string; permissions: string[] }) => Promise<any>
@walletModule.Getter('getSigner') signer!: any
@bookApiModule.Getter('getSessionWallet') sessionWallet!: string
@bookApiModule.Action('restoreSession') restoreSession!: () => void
Expand Down Expand Up @@ -90,7 +90,10 @@ export default class WalletLayout extends Vue {
if (!this.walletAddress || !this.signer) {
throw new Error('FAILED_TO_CONNECT_WALLET')
}
const signature = await this.signMessageMemo('authorize', SIGN_AUTHORIZATION_PERMISSIONS)
const signature = await this.signMessageMemo({
action: 'authorize',
permissions: SIGN_AUTHORIZATION_PERMISSIONS,
});
if (!signature) {
throw new Error('SIGNING_REJECTED')
}
Expand Down
7 changes: 5 additions & 2 deletions pages/auth/redirect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class RedirectPage extends Vue {
@walletModule.Action('initWallet') initWallet!: (params: { method: any; accounts: any; offlineSigner?: any }) => Promise<any>
@walletModule.Action('disconnectWallet') disconnectWallet!: () => void
@walletModule.Action('handleConnectorRedirect') handleConnectorRedirect!: (params: { method: string; params: any }) => Promise<any>
@walletModule.Action('signMessageMemo') signMessageMemo!: (action: string, permissions?: string[]) => Promise<any>
@walletModule.Action('signMessageMemo') signMessageMemo!: (params: { action: string; permissions: string[] }) => Promise<any>
@walletModule.Getter('getSigner') signer!: any
@walletModule.Getter('getWalletAddress') currentAddress!: string

Expand Down Expand Up @@ -53,7 +53,10 @@ export default class RedirectPage extends Vue {
if (!this.currentAddress || !this.signer) {
throw new Error('FAILED_TO_CONNECT_WALLET')
}
const signature = await this.signMessageMemo('authorize', SIGN_AUTHORIZATION_PERMISSIONS)
const signature = await this.signMessageMemo({
action: 'authorize',
permissions: SIGN_AUTHORIZATION_PERMISSIONS,
});
if (!signature) {
throw new Error('SIGNING_REJECTED')
}
Expand Down
2 changes: 1 addition & 1 deletion store/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export default class Wallet extends VuexModule {
}

@Action
async signMessageMemo(action: string, permissions?: string[]) {
async signMessageMemo({ action, permissions }: { action: string, permissions?: string[] }) {
if (!this.signer || !this.address) {
await this.initIfNecessary()
}
Expand Down
8 changes: 7 additions & 1 deletion utils/auth.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { jwtDecode } from "jwt-decode";
import { SIGN_AUTHORIZATION_PERMISSIONS } from "~/constant";

const AUTH_SESSION_KEY = 'likecoin_nft_book_press_token'

export function checkJwtTokenValidity (token: string) {
try {
const decoded = jwtDecode(token);
return decoded?.exp && decoded.exp * 1000 > Date.now();
if (!decoded) {
return false;
}
const isExpired = decoded.exp && decoded.exp * 1000 < Date.now();
const isMatchPermissions = (decoded as any).permissions === SIGN_AUTHORIZATION_PERMISSIONS;
return !isExpired && isMatchPermissions;
} catch (error) {
console.error(error);

Check warning on line 16 in utils/auth.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 18)

Unexpected console statement
return false;
}
}
Expand Down
Loading