-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding permissions checks to apollo (#307)
- Loading branch information
1 parent
70dd8c5
commit e9d07c9
Showing
4 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { tryit } from 'radash'; | ||
import { PlatformPermissions } from '../../sdk'; | ||
import { client } from './client'; | ||
|
||
// NOTE: These will be used in the UI, so they should be user-friendly. | ||
const INVALID_API_TOKEN_MESSAGE = 'Invalid API Token'; | ||
|
||
export const makePermissions = (): PlatformPermissions => { | ||
return { | ||
validate: async ({ auth }) => { | ||
const [err, result] = await tryit(client.auth.health)(auth, {}); | ||
if (err || !result.data.is_logged_in) { | ||
console.warn({ | ||
message: 'Failed to validate permissions for Apollo', | ||
metadata: { error: err, result }, | ||
}); | ||
return { | ||
valid: false, | ||
errorMessage: INVALID_API_TOKEN_MESSAGE, | ||
}; | ||
} | ||
return { | ||
valid: true, | ||
errorMessage: null, | ||
}; | ||
}, | ||
}; | ||
}; | ||
|
||
export const permissions = makePermissions(); |