getGoogleDriveBackupReadiness is a pre-flight check that tells you whether the user’s linked Google account has the OAuth scopes required to back up MPC key shares to Google Drive. Use it to detect — and recover from — missing-scope situations before triggering an MPC reshare ceremony, so you don’t burn a ceremony on an upload that will fail.
It pairs with the Google Drive backup setup as the first layer of a two-layer defense: pre-flight readiness (this function) catches the common cases; post-flight error inspection (via isInsufficientGoogleDriveScopesError) handles legacy tokens captured before scope tracking was introduced.
Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
client | DynamicClient (optional) | The Dynamic client instance. Only required when using multiple clients. |
Returns
Promise<GoogleDriveBackupReadiness> — resolves to the readiness result.
Failures of the underlying access-token fetch propagate as Promise rejections — the caller is expected to surface or retry them.
GoogleDriveBackupReadiness
| Field | Description |
|---|---|
status | 'ready' when stored scopes include both required Drive scopes; 'needs-access' when backup is unlikely to succeed without user intervention. |
missingScopes | Scopes the user still needs to grant. See the sub-case table below for how to interpret this in conjunction with status. |
accessToken | The user’s current Google OAuth access token, if one was successfully fetched. Absent when no Google account is linked. |
'needs-access' status covers three distinct sub-cases, distinguishable by missingScopes:
| Sub-case | missingScopes | Description |
|---|---|---|
| No Google account linked | Full required set (GOOGLE_DRIVE_BACKUP_REQUIRED_SCOPES) | The user hasn’t linked Google yet. Render copy directly without checking the empty case. |
| Some scopes missing | Subset of required scopes | The user linked Google but didn’t grant every required Drive scope on the consent screen. |
| Legacy tokens (unknown scopes) | Empty array | Token was captured before scope tracking shipped. Force a fresh consent to populate the scopes column for subsequent calls. |
Recovering from 'needs-access'
Recovery is the caller’s responsibility — re-link the user’s Google account so the required Drive scopes are granted, then call getGoogleDriveBackupReadiness again before retrying the backup. Use signInWithSocialRedirect with the google provider:
Examples
Pre-flight check before backup
- JavaScript
- React
Post-flight scope-error recovery
For legacy tokens where pre-flight cannot prove the upload will fail (missingScopes is empty under 'needs-access', or stored scopes were never recorded), wrap the backup attempt in a try/catch and use isInsufficientGoogleDriveScopesError to detect the scope-denied failure mode.
Related helpers
The same module also exports a few primitives for callers who want to build their own checks:| Export | Description |
|---|---|
GOOGLE_DRIVE_BACKUP_REQUIRED_SCOPES | Readonly tuple of the OAuth scopes required for Google Drive backup. |
findMissingGoogleDriveBackupScopes(granted) | Returns the subset of GOOGLE_DRIVE_BACKUP_REQUIRED_SCOPES that are not present in granted. |
hasAllGoogleDriveBackupScopes(granted) | Convenience boolean — true when every required scope is present in granted. |
isInsufficientGoogleDriveScopesError(err) | Type guard for Errors thrown by the backup flow when access was denied due to missing/insufficient scopes. |