Cliente

session()

api.session() → Promise<{ id, storageId } | null>

Quale sessione questo client sta using. Lee prima la cache, e chiede al server solo quando la cache non sa dire.

cache firstnever throwsnull before the first exchange
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Retorno

{
  id: "…",          // the session id
  storageId: "…"    // the storage this session is bound to, or null
}
{
    "id": "…",          # the session id
    "storageId": "…",   # the storage this session is bound to, or None
}
idstring

- Ce? Revore Session() e il

storageIdstring|null

Quale stoccatura il server riconosce questo processo come. Per una máquina, é así que mantiene una identitä a travers reinizios.

Como risponde

Stat de cacheCe succeda
Un id di sessione è cachedretornò d'immediat — senza rete
Un gèn è cached, ma no idle sessioni attive sono listate, e la unita al medès stoccage è igual
Que la lista failesnull — il fallimento è inghiottito, non gettato
- Nada è cachednull, e nulla è scambiato per scopri-lo

La seconda fila è il motivo per cui questo metodo può essere più lento di quanto pare su un client restaurat da un cache ancestrale. La prima fila è il cas normal.

Non crea una sessione, e non lança mai

Su un client fria risponde null. Fai prima una chiamata ordinaria — getUser() è la meno barata — e il cambio avviene là. Perché inghiote il suo proprio fallimento, un null mai dice que la rete è abatida; dice que il metodo non puèt nomire una sessione.

const fresh = new IaGenify({ apiKey });

await fresh.session();      // null — nothing has been exchanged
await fresh.getUser();      // this is what exchanges
await fresh.session();      // { id, storageId }
fresh = IaGenify(api_key=api_key)

fresh.session()     # None — nothing has been exchanged
fresh.get_user()    # this is what exchanges
fresh.session()     # {"id", "storageId"}

Finalidade

  • Mostrando quale sessione un processo è in esecuzione come — in un dashboard, o in una línea de log al bott.
  • Passando l'id a revokeSession(), incluso per terminare questa sessione da un altro lugar.
  • Lectura storageId per confermare il server ha riconosciuto questa macchina come quella che si aspettava, invece di registrare un secondo.

Una linea a bott

const [user, session] = await Promise.all([api.getUser(), api.session()]);

console.log(
  `iagenify · ${user?.email} · session ${session?.id ?? "none"} · storage ${session?.storageId ?? "none"}`,
);
user, session = api.get_user(), api.session()

print(
    f"iagenify · {(user or {}).get('email')} · "
    f"session {(session or {}).get('id', 'none')} · storage {(session or {}).get('storageId') or 'none'}"
)

Confirmando una macchina, non tante

Una macchina mantiene la stessa identitât con l'invio di suo storageId di nuovo sul proximo canvà. Quando un implementamento perde la cache di sessione in ogni reinizio, ogni boot registra un nuovo — e che appare come un mucchio di stoccajs quasi-identica.

const before = (await api.session())?.storageId;

// … restart the process, with the same sessionPath …

const after = (await api.session())?.storageId;
// Same value: one machine. A different one: the session cache did not survive.
before = (api.session() or {}).get("storageId")

# … restart the process, with the same session_path …

after = (api.session() or {}).get("storageId")
# Same value: one machine. A different one: the session cache did not survive.
Un container senza seduzione persistente registra una volta per botto

Montare la via di sessione, o passare un storage che controli. Altrimenti, ogni reinizio è una macchina nova al server, e l'identitât che tu eras basando su cambis sotto tu.

Quando non persistere sessioni

In un tempo di runtime senza stoccatura duratura la sessione vive in memoria, per il tempo in cui l'isolat — so session() risposte per questo isolat e nò più. Quest è una proprietà del negozio, non di questo metodo, e un negozio che fornir lo cambia.

Fine

const current = await api.session();

await api.auth.logout();              // this one
await api.auth.revokeSession(id);     // another, by id
current = api.session()

api.auth.logout()                    # this one
api.auth.revoke_session(session_id)  # another, by id

Nota l'assimetria: questo metodo ti da tu Id. Un'altra macchina id non è qualcosa SDK listas — quando si desidera una máquina shut out, revocare la chave che detiene.