Skip to content

Commit

Permalink
fix: incorrect creds on ui (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinsandilya authored Jun 30, 2023
1 parent 8206432 commit 539ff55
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
14 changes: 12 additions & 2 deletions packages/backend/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ router.post('/clerk/webhook', async (req, res) => {
});

router.post('/internal/account', async (req, res) => {
const userId = req.body.userId;
res.send(await AuthService.getAccountForUser(userId));
try {
const userId = req.body.userId;
const result = await AuthService.getAccountForUser(userId);
if (result?.error) {
res.status(400).send(result);
} else {
res.send(result);
}
} catch (error) {
console.error('Could not get account for user', error);
res.status(500).send({ error: 'Internal server error' });
}
});

router.use('/crm', cors(), revertAuthMiddleware(), crmRouter);
Expand Down
30 changes: 16 additions & 14 deletions packages/backend/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ class AuthService {
const url = 'https://api.hubapi.com/oauth/v1/token';
const formData = {
grant_type: 'refresh_token',
client_id:
connection.app.app_client_id || config.HUBSPOT_CLIENT_ID,
client_secret:
connection.app.app_client_secret || config.HUBSPOT_CLIENT_SECRET,
client_id: connection.app.app_client_id || config.HUBSPOT_CLIENT_ID,
client_secret: connection.app.app_client_secret || config.HUBSPOT_CLIENT_SECRET,
redirect_uri: `${config.OAUTH_REDIRECT_BASE}/hubspot`,
refresh_token: connection.tp_refresh_token,
};
Expand Down Expand Up @@ -53,10 +51,8 @@ class AuthService {
const url = `${connection.tp_account_url}/oauth/v2/token`;
const formData = {
grant_type: 'refresh_token',
client_id:
connection.app.app_client_id || config.ZOHOCRM_CLIENT_ID,
client_secret:
connection.app.app_client_secret || config.ZOHOCRM_CLIENT_SECRET,
client_id: connection.app.app_client_id || config.ZOHOCRM_CLIENT_ID,
client_secret: connection.app.app_client_secret || config.ZOHOCRM_CLIENT_SECRET,
redirect_uri: `${config.OAUTH_REDIRECT_BASE}/zohocrm`,
refresh_token: connection.tp_refresh_token,
};
Expand Down Expand Up @@ -89,10 +85,8 @@ class AuthService {
const url = `https://login.salesforce.com/services/oauth2/token`;
const formData = {
grant_type: 'refresh_token',
client_id:
connection.app.app_client_id || config.SFDC_CLIENT_ID,
client_secret:
connection.app.app_client_secret || config.SFDC_CLIENT_SECRET,
client_id: connection.app.app_client_id || config.SFDC_CLIENT_ID,
client_secret: connection.app.app_client_secret || config.SFDC_CLIENT_SECRET,
redirect_uri: `${config.OAUTH_REDIRECT_BASE}/sfdc`,
refresh_token: connection.tp_refresh_token,
};
Expand Down Expand Up @@ -183,8 +177,11 @@ class AuthService {
}
return response;
}
async getAccountForUser(userId: string) {
return await prisma.users.findFirst({
async getAccountForUser(userId: string): Promise<any> {
if (!userId) {
return { error: 'Bad request' };
}
const account = await prisma.users.findFirst({
where: {
id: userId,
account: {
Expand All @@ -193,6 +190,11 @@ class AuthService {
},
select: { account: true },
});
if (!account) {
return { error: 'Account does not exist' };
}

return account;
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/client/src/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ const Home = () => {
const [isLoading, setLoading] = useState<boolean>(false);

useEffect(() => {
const headers = new Headers();
headers.append('Content-Type', 'application/json');

const data = JSON.stringify({
userId: user.user?.id,
});

const requestOptions = {
method: 'POST',
body: data,
headers: headers,
};
setLoading(true);
fetch(`${REVERT_BASE_API_URL}/internal/account`, requestOptions)
Expand Down

2 comments on commit 539ff55

@vercel
Copy link

@vercel vercel bot commented on 539ff55 Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

revert-react – ./packages/react

revert-react-git-main-revertdev.vercel.app
revert-react.vercel.app
revert-react-revertdev.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 539ff55 Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.