Skip to content

Commit bde2db3

Browse files
committed
feat: Add host permission checks for Firefox sign-in functionality
1 parent 2d4d638 commit bde2db3

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/utils/Permissions.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { getBrowserName } from './Environment'
2+
3+
// Check host permissions before allowing the user to sign in with a provider.
4+
// as Firefox may block the Signin on v3 if the extension does not have host permissions.
5+
export const checkHostPermissions = async () => {
6+
if (getBrowserName() !== 'firefox') {
7+
return true
8+
}
9+
10+
const HOST_PERMISSIONS = chrome.runtime.getManifest().content_scripts || []
11+
const requiredHosts = HOST_PERMISSIONS.flatMap((permission) => {
12+
return permission.matches || []
13+
})
14+
15+
return await chrome.permissions.contains({ origins: requiredHosts })
16+
}
17+
18+
export const requestHostPermissions = async () => {
19+
if (getBrowserName() !== 'firefox') {
20+
return true
21+
}
22+
const HOST_PERMISSIONS = chrome.runtime.getManifest().content_scripts || []
23+
const requiredHosts = HOST_PERMISSIONS.flatMap((permission) => {
24+
return permission.matches || []
25+
})
26+
27+
return await chrome.permissions.request({ origins: requiredHosts })
28+
}

0 commit comments

Comments
 (0)