Skip to content

Commit

Permalink
refactor: add bstk jwt payload validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Nov 9, 2020
1 parent b77635c commit 02ee249
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/app/src/store/onboarding/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { finalizeAuthResponse } from '@common/utils';
import { gaiaUrl } from '@common/constants';
import { doTrackScreenChange } from '@common/track';
import { TransactionVersion } from '@blockstack/stacks-transactions';
import { verifyAuthRequest } from 'blockstack';

export const doSetOnboardingProgress = (status: boolean): OnboardingActions => {
return {
Expand Down Expand Up @@ -107,10 +108,11 @@ const saveAuthRequest = ({
};
};

export function doSaveAuthRequest(
authRequest: string
): ThunkAction<void, AppState, {}, OnboardingActions> {
type DoSaveAuthRequestReturn = ThunkAction<void, AppState, {}, OnboardingActions>;
export function doSaveAuthRequest(authRequest: string): DoSaveAuthRequestReturn {
return async (dispatch, getState) => {
const isValidPayload = await verifyAuthRequest(authRequest);
if (!isValidPayload) throw new Error('JWT auth token is not valid');
const { payload } = decodeToken(authRequest);
const decodedAuthRequest = (payload as unknown) as DecodedAuthRequest;
let appName = decodedAuthRequest.appDetails?.name;
Expand Down

0 comments on commit 02ee249

Please sign in to comment.