Skip to content

Commit

Permalink
Add email to createSession (bluesky-social#760)
Browse files Browse the repository at this point in the history
Add email to createSession and update api to store email in the session object

Co-authored-by: Devin Ivy <[email protected]>
  • Loading branch information
pfrazee and devinivy authored Apr 4, 2023
1 parent eb488b9 commit 25c23b6
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lexicons/com/atproto/server/createSession.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"accessJwt": {"type": "string"},
"refreshJwt": {"type": "string"},
"handle": {"type": "string", "format": "handle"},
"did": {"type": "string", "format": "did"}
"did": {"type": "string", "format": "did"},
"email": {"type": "string"}
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class AtpAgent {
refreshJwt: res.data.refreshJwt,
handle: res.data.handle,
did: res.data.did,
email: opts.email,
}
return res
} catch (e) {
Expand Down Expand Up @@ -125,6 +126,7 @@ export class AtpAgent {
refreshJwt: res.data.refreshJwt,
handle: res.data.handle,
did: res.data.did,
email: res.data.email,
}
return res
} catch (e) {
Expand All @@ -151,6 +153,8 @@ export class AtpAgent {
if (!res.success || res.data.did !== this.session.did) {
throw new Error('Invalid session')
}
this.session.email = res.data.email
this.session.handle = res.data.handle
return res
} catch (e) {
this.session = undefined
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,9 @@ export const schemaDict = {
type: 'string',
format: 'did',
},
email: {
type: 'string',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface OutputSchema {
refreshJwt: string
handle: string
did: string
email?: string
[k: string]: unknown
}

Expand Down
1 change: 1 addition & 0 deletions packages/api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface AtpSessionData {
accessJwt: string
handle: string
did: string
email?: string
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/api/tests/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('agent', () => {
expect(agent.session?.refreshJwt).toEqual(res.data.refreshJwt)
expect(agent.session?.handle).toEqual(res.data.handle)
expect(agent.session?.did).toEqual(res.data.did)
expect(agent.session?.email).toEqual('[email protected]')

const { data: sessionInfo } = await agent.api.com.atproto.server.getSession(
{},
Expand Down Expand Up @@ -91,6 +92,7 @@ describe('agent', () => {
expect(agent2.session?.refreshJwt).toEqual(res1.data.refreshJwt)
expect(agent2.session?.handle).toEqual(res1.data.handle)
expect(agent2.session?.did).toEqual(res1.data.did)
expect(agent2.session?.email).toEqual('[email protected]')

const { data: sessionInfo } =
await agent2.api.com.atproto.server.getSession({})
Expand Down
1 change: 1 addition & 0 deletions packages/pds/src/api/com/atproto/server/createSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function (server: Server, ctx: AppContext) {
body: {
did: user.did,
handle: user.handle,
email: user.email,
accessJwt: access.jwt,
refreshJwt: refresh.jwt,
},
Expand Down
3 changes: 3 additions & 0 deletions packages/pds/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,9 @@ export const schemaDict = {
type: 'string',
format: 'did',
},
email: {
type: 'string',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface OutputSchema {
refreshJwt: string
handle: string
did: string
email?: string
[k: string]: unknown
}

Expand Down
1 change: 1 addition & 0 deletions packages/pds/tests/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ describe('account', () => {
expect(typeof jwt).toBe('string')
expect(res.data.handle).toBe('alice.test')
expect(res.data.did).toBe(did)
expect(res.data.email).toBe(email)
})

it('can perform authenticated requests', async () => {
Expand Down

0 comments on commit 25c23b6

Please sign in to comment.