Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable updateEmail with no token & no app password #1715

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/pds/src/api/com/atproto/server/updateEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import disposable from 'disposable-email'

export default function (server: Server, ctx: AppContext) {
server.com.atproto.server.updateEmail({
auth: ctx.accessVerifierCheckTakedown,
auth: ctx.accessVerifierNotAppPassword,
handler: async ({ auth, input }) => {
const did = auth.credentials.did
const { token, email } = input.body
Expand All @@ -18,10 +18,7 @@ export default function (server: Server, ctx: AppContext) {
if (!user) {
throw new InvalidRequestError('user not found')
}
if (!user.emailConfirmedAt) {
throw new InvalidRequestError('email must be confirmed (temporary)')
}
// require valid token
// require valid token if user email is confirmed
if (user.emailConfirmedAt) {
if (!token) {
throw new InvalidRequestError(
Expand Down
30 changes: 4 additions & 26 deletions packages/pds/tests/email-confirmation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,50 +60,28 @@ describe('email confirmation', () => {
expect(session.data.emailConfirmed).toEqual(false)
})

it('disallows email update when unverified', async () => {
it('allows email update without token when unverified', async () => {
const res = await agent.api.com.atproto.server.requestEmailUpdate(
undefined,
{ headers: sc.getHeaders(alice.did) },
)
expect(res.data.tokenRequired).toBe(false)

const attempt = agent.api.com.atproto.server.updateEmail(
await agent.api.com.atproto.server.updateEmail(
{
email: '[email protected]',
},
{ headers: sc.getHeaders(alice.did), encoding: 'application/json' },
)
await expect(attempt).rejects.toThrow()
const session = await agent.api.com.atproto.server.getSession(
{},
{ headers: sc.getHeaders(alice.did) },
)
expect(session.data.email).toEqual(alice.email)
expect(session.data.email).toEqual('new-alice@example.com')
expect(session.data.emailConfirmed).toEqual(false)
alice.email = session.data.email
})

// it('allows email update without token when unverified', async () => {
// const res = await agent.api.com.atproto.server.requestEmailUpdate(
// undefined,
// { headers: sc.getHeaders(alice.did) },
// )
// expect(res.data.tokenRequired).toBe(false)

// await agent.api.com.atproto.server.updateEmail(
// {
// email: '[email protected]',
// },
// { headers: sc.getHeaders(alice.did), encoding: 'application/json' },
// )
// const session = await agent.api.com.atproto.server.getSession(
// {},
// { headers: sc.getHeaders(alice.did) },
// )
// expect(session.data.email).toEqual('[email protected]')
// expect(session.data.emailConfirmed).toEqual(false)
// alice.email = session.data.email
// })

let confirmToken

it('requests email confirmation', async () => {
Expand Down