Function compareScopes

  • c.

    Parameters

    • scopesToCompare: string[]

      The list of scopes present in the token.

    • requestedScopes: string[] = []

      The scopes needed for the operation. Default to an empty array.

    • Optionaluser: UserIdResolvable

      The user ID associated with the token. This is used in the error message if scopes are missing.

    Returns void

    This function checks if the provided token has all the necessary scopes for an operation. If the token does not contain any of the requested scopes, a MissingScopeError is thrown for the caller to handle.

    MissingScopeError If the token does not include the required scopes.

    try {
    compareScopes(['oauth-user-show', 'oauth-donation-index'], ['oauth-custom_alert-store'], 12345);
    } catch (error) {
    if (error instanceof MissingScopeError) {
    console.error('Missing scopes:', error.missingScopes);
    }
    }