Skip to content

Commit 96f19f9

Browse files
author
Nick Bragdon
committed
Removing bene information when bene has denied access
1 parent 32ebcd2 commit 96f19f9

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

server/src/routes/Authorize.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ import Settings from '../entities/Settings';
55
import db from '../utils/db';
66
import { getAccessToken, generateAuthorizeUrl } from '../utils/bb2';
77
import { getBenefitData } from './Data';
8-
import { getLoggedInUser } from 'src/utils/user';
8+
import { clearBB2Data, getLoggedInUser } from 'src/utils/user';
9+
10+
const BENE_DENIED_ACCESS = 'access_denied';
911

1012

1113
export async function authorizationCallback(req: Request, res: Response) {
1214
try {
15+
16+
if (req.quey.error === BENE_DENIED_ACCESS) {
17+
const loggedInUser = getLoggedInUser(db);
18+
// clear all saved claims data since the bene has denied access for the application
19+
clearBB2Data(loggedInUser);
20+
loggedInUser.errors.push(BENE_DENIED_ACCESS);
21+
throw new Error('Beneficiary denied application access to their data');
22+
}
1323

1424
if (!req.query.code) {
1525
throw new Error('Response was missing access code');

server/src/utils/db.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export interface UserInfo {
1616
export interface User {
1717
authToken?: AuthorizationToken,
1818
userInfo: UserInfo,
19-
eobData?: any
19+
eobData?: any,
20+
errors: string[]
2021
}
2122
export interface DB {
2223
patients: object,
@@ -51,7 +52,8 @@ const db: DB = {
5152
userName: 'jdoe29999',
5253
pcp: 'Dr. Hibbert',
5354
primaryFacility: 'Springfield General Hospital'
54-
}
55+
},
56+
errors: []
5557
}],
5658
codeChallenges: {},
5759
codeChallenge: {

server/src/utils/user.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DB } from "./db";
1+
import { DB, User } from "./db";
22

33
/* DEVELOPER NOTES:
44
* Here we are literally just grabbing the first user
@@ -9,4 +9,9 @@ import { DB } from "./db";
99
*/
1010
export function getLoggedInUser(db : DB) {
1111
return db.users[0];
12+
}
13+
14+
export function clearBB2Data(user: User) {
15+
user.authToken = undefined;
16+
user.eobData = undefined;
1217
}

0 commit comments

Comments
 (0)