Skip to content

Commit

Permalink
api: update login/resumeSession examples in README (bluesky-social#1634)
Browse files Browse the repository at this point in the history
* api: update login/resumeSession examples in README

* Update packages/api/README.md

Co-authored-by: Daniel Holmgren <[email protected]>

---------

Co-authored-by: Daniel Holmgren <[email protected]>
  • Loading branch information
bnewbold and dholms authored Sep 21, 2023
1 parent d23f5ec commit 462de21
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,28 @@ 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) => {
// store the session-data for reuse
},
})

await agent.login({ identifier: '[email protected]', password: 'hunter2' })
await agent.resumeSession(savedSessionData)
// create a new account on the server
await agent.createAccount({
email: '[email protected]',
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: '[email protected]', password: 'hunter2' })
```

### API calls
Expand Down

0 comments on commit 462de21

Please sign in to comment.