From ccc25b0aa7a3fb69cd8d79dd07095de2657a5b39 Mon Sep 17 00:00:00 2001 From: Tom Andrews Date: Fri, 13 Nov 2020 16:24:31 +0000 Subject: [PATCH] Allow for emails to be null (#11) When privacy settings are enabled in github then even with the user email scope enabled it isn't returned. * Allow for emails to be null * Set correct typings --- src/index.test.ts | 11 +++++++++++ src/index.ts | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index d33b909..363f76a 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -51,6 +51,17 @@ describe("next-auth-dynamodb", () => { expect(readUser).toStrictEqual(savedUser); }); + it("should not blow up if the user's email address is null", async () => { + const adapter = await nextAuthDynamodb.getAdapter(opts); + const savedUser = await adapter.createUser({ + email: null, + name: "Null Email", + image: "foo.png", + }); + const readUser = await adapter.getUser(savedUser.id); + expect(readUser).toStrictEqual(savedUser); + }); + it("should be able to link a user to the a provider and return the user", async () => { const adapter = await nextAuthDynamodb.getAdapter(opts); const savedUser = await adapter.createUser({ diff --git a/src/index.ts b/src/index.ts index 2675ef1..33877bf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,7 @@ const logger = pino({ enabled: LOGGING_ENABLED }); export interface User { id: string; name: string; - email: string; + email?: string; image: string; emailVerified?: boolean; } @@ -19,7 +19,7 @@ export const userDefinition: Options = { hashKey: "id", schema: Joi.object({ id: Omanyd.types.id(), - email: Joi.string().required(), + email: Joi.string(), name: Joi.string(), image: Joi.string(), emailVerified: Joi.boolean(), @@ -57,7 +57,7 @@ const AccountStore = Omanyd.define({ interface Profile { name: string; - email: string; + email: string | null; image: string; emailVerified?: boolean; } @@ -98,7 +98,7 @@ const adapter: Adapter = { log("createUser", { profile }); const { email, emailVerified, name, image } = profile; const savedUser = await UserStore.create({ - email, + email: email ? email : undefined, emailVerified, name, image,