diff --git a/examples/full-example/src/pages/api/auth/[...nextauth].ts b/examples/full-example/src/pages/api/auth/[...nextauth].ts index 64a156d..008ed87 100644 --- a/examples/full-example/src/pages/api/auth/[...nextauth].ts +++ b/examples/full-example/src/pages/api/auth/[...nextauth].ts @@ -1,6 +1,6 @@ import NextAuth, { NextAuthOptions } from 'next-auth'; import GitHub from 'next-auth/providers/github'; -import { SanityAdapter, SanityCredentials } from '../../../../../../dist'; +import { SanityAdapter, SanityCredentials } from 'next-auth-sanity'; import { client } from '../../../libs/sanity'; const options: NextAuthOptions = { diff --git a/examples/full-example/src/pages/api/sanity/signUp.ts b/examples/full-example/src/pages/api/sanity/signUp.ts index 560bf33..b45811a 100644 --- a/examples/full-example/src/pages/api/sanity/signUp.ts +++ b/examples/full-example/src/pages/api/sanity/signUp.ts @@ -1,4 +1,4 @@ -import { signUpHandler } from '../../../../../../dist'; +import { signUpHandler } from 'next-auth-sanity'; import { client } from '../../../libs/sanity'; export default signUpHandler(client); diff --git a/examples/full-example/src/pages/credentials.tsx b/examples/full-example/src/pages/credentials.tsx index afb2017..db0f942 100644 --- a/examples/full-example/src/pages/credentials.tsx +++ b/examples/full-example/src/pages/credentials.tsx @@ -1,6 +1,6 @@ import React, { FC, useState } from 'react'; import { useSession, signOut, signIn } from 'next-auth/react'; -import { signUp } from '../../../../dist/client'; +import { signUp } from 'next-auth-sanity/client'; const Credentials: FC = () => { const [email, setEmail] = useState(''); @@ -19,7 +19,8 @@ const Credentials: FC = () => { await signIn('sanity-login', { redirect: false, - email + email, + password }); }; diff --git a/examples/full-example/tsconfig.json b/examples/full-example/tsconfig.json index 37588c0..93a83a4 100644 --- a/examples/full-example/tsconfig.json +++ b/examples/full-example/tsconfig.json @@ -1,11 +1,7 @@ { "compilerOptions": { "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], + "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "strict": false, @@ -16,14 +12,8 @@ "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, - "jsx": "preserve", + "jsx": "preserve" }, - "include": [ - "next-env.d.ts", - "**/*.ts", - "**/*.tsx" - ], - "exclude": [ - "node_modules" - ] + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], + "exclude": ["node_modules"] } diff --git a/package.json b/package.json index ee16f0a..7f47f94 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "next-auth-sanity", "description": "NextAuth Adapter for Sanity", - "version": "1.4.3", + "version": "1.4.4", "main": "index.js", "types": "index.d.ts", "repository": { diff --git a/src/adapter.ts b/src/adapter.ts index 0e332c9..753e3cf 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -20,21 +20,17 @@ export function SanityAdapter( ): Adapter { return { async createUser(profile) { - const user = await client.create({ + const { _id, ...user } = await client.create({ _id: `user.${uuid()}`, _type: options.schemas.user, - email: profile.email, - name: profile.name, - image: profile.image + ...profile }); return { - id: user._id, + id: _id, emailVerified: null, - email: user.email, - name: user.name, - image: user.image - } as AdapterUser; + ...user + }; }, async getUser(id) { @@ -86,22 +82,13 @@ export function SanityAdapter( async deleteSession() {}, async updateUser(user) { - const { id, name, email, image } = user; - - const newUser = await client - .patch(id!) - .set({ - name, - email, - image - }) - .commit(); + const newUser = await client.patch(user.id!).set(user).commit(); return { id: newUser._id, ...newUser, emailVerified: null - } as AdapterUser; + }; }, async getUserByEmail(email) { diff --git a/src/client.ts b/src/client.ts index 2c20039..f9951e2 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,11 +1,11 @@ import type { User } from 'next-auth'; -export interface SignUpPayload { +export type SignUpPayload = { email: string; password: string; name?: string; image?: string; -} +} & Record; export const signUp = async (payload: SignUpPayload): Promise => { const res = await fetch('/api/sanity/signUp', { diff --git a/src/credentials.ts b/src/credentials.ts index 04ac52f..c1f2da7 100644 --- a/src/credentials.ts +++ b/src/credentials.ts @@ -10,7 +10,7 @@ type CredentialsConfig = ReturnType; export const signUpHandler = (client: SanityClient, userSchema: string = 'user') => async (req: any, res: any) => { - const { email, password, name, image } = req.body; + const { email, password, name, image, ...userData } = req.body; const user = await client.fetch(getUserByEmailQuery, { userSchema, @@ -22,19 +22,19 @@ export const signUpHandler = return; } - const newUser = await client.create({ + const { password: _, ...newUser } = await client.create({ _id: `user.${uuid()}`, _type: userSchema, email, password: await argon2.hash(password), name, - image + image, + ...userData }); res.json({ - email: newUser.email, - name: newUser.name, - image: newUser.image + id: newUser._id, + ...newUser }); }; @@ -57,7 +57,7 @@ export const SanityCredentials = ( } }, async authorize(credentials) { - const user = await client.fetch(getUserByEmailQuery, { + const { _id, ...user } = await client.fetch(getUserByEmailQuery, { userSchema, email: credentials?.email }); @@ -66,10 +66,8 @@ export const SanityCredentials = ( if (await argon2.verify(user.password, credentials?.password!)) { return { - email: user.email, - name: user.name, - image: user.image, - id: user._id + id: _id, + ...user }; }