Skip to content

Commit 3863d0c

Browse files
committed
feat(accounts): warn when missing scopes
Signed-off-by: Adam Setch <[email protected]>
1 parent 5c3f303 commit 3863d0c

File tree

4 files changed

+123
-4
lines changed

4 files changed

+123
-4
lines changed

src/renderer/routes/Accounts.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AlertFillIcon,
23
FeedPersonIcon,
34
KeyIcon,
45
MarkGithubIcon,
@@ -23,6 +24,7 @@ import { type Account, IconColor, Size } from '../types';
2324
import { getAccountUUID, refreshAccount } from '../utils/auth/utils';
2425
import { cn } from '../utils/cn';
2526
import { updateTrayIcon, updateTrayTitle } from '../utils/comms';
27+
import { Constants } from '../utils/constants';
2628
import {
2729
openAccountProfile,
2830
openDeveloperSettings,
@@ -78,7 +80,7 @@ export const AccountsRoute: FC = () => {
7880
className="mb-4 flex items-center justify-between rounded-md bg-gray-100 p-2 dark:bg-gray-sidebar"
7981
>
8082
<div className="ml-2 text-xs">
81-
<div>
83+
<div className="flex flex-1 items-center gap-2">
8284
<button
8385
type="button"
8486
className="flex flex-1 gap-2 items-center justify-center mb-1 cursor-pointer text-sm font-semibold"
@@ -99,6 +101,25 @@ export const AccountsRoute: FC = () => {
99101
({account.user?.name})
100102
</span>
101103
</button>
104+
105+
<span
106+
hidden={
107+
account.method === 'Personal Access Token' &&
108+
account.hasRequiredScopes === true
109+
}
110+
className="text-xs font-medium italic"
111+
>
112+
<button
113+
type="button"
114+
className="cursor-default"
115+
title={`This account is missing one or more required scopes: \n\t- ${Constants.AUTH_SCOPE.join('\n\t- ')}`}
116+
>
117+
<AlertFillIcon
118+
size={Size.XSMALL}
119+
className={IconColor.RED}
120+
/>
121+
</button>
122+
</span>
102123
</div>
103124
<div>
104125
<button

src/renderer/routes/__snapshots__/Accounts.test.tsx.snap

Lines changed: 96 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface Account {
5050
hostname: Hostname;
5151
token: Token;
5252
user: GitifyUser | null;
53+
hasRequiredScopes?: boolean;
5354
}
5455

5556
export type SettingsValue =

src/renderer/utils/auth/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ export async function refreshAccount(account: Account): Promise<Account> {
169169
account.version = extractHostVersion(
170170
res.headers['x-github-enterprise-version'],
171171
);
172+
173+
account.hasRequiredScopes = res.headers['x-oauth-scopes']
174+
.split(',')
175+
.includes(Constants.AUTH_SCOPE);
172176
} catch (err) {
173177
log.error(
174178
'[refreshAccount]: failed to refresh account for user',

0 commit comments

Comments
 (0)