forked from bluesky-social/atproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: update login/resumeSession examples in README (bluesky-social#1634)
* 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
Showing
1 changed file
with
10 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|