Files
dashlibstorage/API.google_auth.md
2026-11-02 00:19:21 +01:00

169 lines
3.5 KiB
Markdown

# google_auth
This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`.
## `google_auth.add`
*Source: `src/store/google_auth/add.js`*
Adds a new allowed Google auth email (registration). Pending `autoinvite` rows for this email are consumed in the same transaction: each is deleted and turned into a `companyuser` with the invited role.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `email` | `string` | The email address to allow. |
**Returns**
`Promise<number>` — The id of the created Google auth row.
**Example**
```js
const id = await store.google_auth.add('user@example.com');
// => 1
```
## `google_auth.getByEmail`
*Source: `src/store/google_auth/getByEmail.js`*
Returns a Google auth row by email.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `email` | `string` | The email address. |
**Returns**
`Promise<object|undefined>` — The Google auth row, or `undefined` if not found.
**Example**
```js
const auth = await store.google_auth.getByEmail('user@example.com');
// => { id, email, ... }
```
## `google_auth.getById`
*Source: `src/store/google_auth/getById.js`*
Returns a Google auth row by its id.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth row. |
**Returns**
`Promise<object|undefined>` — The Google auth row, or `undefined` if not found.
**Example**
```js
const auth = await store.google_auth.getById(42);
// => { id, email, ... }
```
## `google_auth.listAllowedEmails`
*Source: `src/store/google_auth/listAllowedEmails.js`*
Lists all allowed Google auth emails.
**Returns**
`Promise<Array<{id: number, email: string}>>` — The allowed emails.
**Example**
```js
const emails = await store.google_auth.listAllowedEmails();
// => [{ id, email }]
```
## `google_auth.removeAllowedEmail`
*Source: `src/store/google_auth/removeAllowedEmail.js`*
Removes an allowed Google auth email.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `email` | `string` | The email address to remove. |
**Returns**
`Promise<void>`
**Example**
```js
await store.google_auth.removeAllowedEmail('user@example.com');
```
## `google_auth.setProfile`
*Source: `src/store/google_auth/setProfile.js`*
Updates the profile (picture, picture binary, sub) of a Google auth user.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `input` | `object` | The profile input. |
| `[input.picture]` | `string` | The picture URL. |
| `[input.pictureBinary]` | `Buffer` | The picture binary. |
| `[input.sub]` | `string` | The Google sub identifier. |
**Returns**
`Promise<void>`
**Throws**
`Error` — If the user is not found or the picture binary is invalid.
**Example**
```js
await store.google_auth.setProfile(42, { picture: 'url', pictureBinary: buffer, sub: 'sub' });
```
## `google_auth.setSelectedCompany`
*Source: `src/store/google_auth/setSelectedCompany.js`*
Sets the currently selected company for a Google auth user. The user must be a member (`companyuser`) of the company.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `companyId` | `number` | The id of the company to select. |
**Returns**
`Promise<void>`
**Throws**
`Error` — 'Not authorized' if the user is not a member of the company.
**Example**
```js
await store.google_auth.setSelectedCompany(42, 1);
```