From 462de219eedc3c862ca6f88ec130d55c2f6af954 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Wed, 20 Sep 2023 19:15:12 -0700 Subject: [PATCH] api: update login/resumeSession examples in README (#1634) * api: update login/resumeSession examples in README * Update packages/api/README.md Co-authored-by: Daniel Holmgren --------- Co-authored-by: Daniel Holmgren --- packages/api/README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/api/README.md b/packages/api/README.md index fdfcbc48b73..069bdb50a5e 100644 --- a/packages/api/README.md +++ b/packages/api/README.md @@ -31,6 +31,8 @@ Log into a server or create accounts using these APIs. You'll need an active ses ```typescript import { BskyAgent, AtpSessionEvent, AtpSessionData } from '@atproto/api' + +// configure connection to the server, without account authentication const agent = new BskyAgent({ service: 'https://example.com', persistSession: (evt: AtpSessionEvent, sess?: AtpSessionData) => { @@ -38,13 +40,19 @@ const agent = new BskyAgent({ }, }) -await agent.login({ identifier: 'alice@mail.com', password: 'hunter2' }) -await agent.resumeSession(savedSessionData) +// create a new account on the server await agent.createAccount({ email: 'alice@mail.com', password: 'hunter2', handle: 'alice.example.com', + inviteCode: 'some-code-12345-abcde', }) + +// if an existing session (accessed with 'agent.session') was securely stored previously, then reuse that +await agent.resumeSession(savedSessionData) + +// if no old session was available, create a new one by logging in with password (App Password) +await agent.login({ identifier: 'alice@mail.com', password: 'hunter2' }) ``` ### API calls