Skip to content
This repository has been archived by the owner on May 22, 2022. It is now read-only.

Commit

Permalink
Allow for emails to be null (#11)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tgandrews authored Nov 13, 2020
1 parent e93145d commit ccc25b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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(),
Expand Down Expand Up @@ -57,7 +57,7 @@ const AccountStore = Omanyd.define<Account>({

interface Profile {
name: string;
email: string;
email: string | null;
image: string;
emailVerified?: boolean;
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ccc25b0

Please sign in to comment.