Skip to content

Commit

Permalink
fix: updates sanity and next auth to last version (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedeya authored Feb 26, 2023
1 parent 6eb7ecc commit 40db69f
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 280 deletions.
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf index.js index.d.ts queries.js queries.ts queries.d.ts adapter.js adapter.ts adapter.d.ts client.js client.ts client.d.ts schemas.js schemas.ts schemas.d.ts credentials.js credentials.ts credentials.d.ts",
"prepublishOnly": "yarn build"
"prepublishOnly": "yarn build",
"postpublish": "yarn clean"
},
"devDependencies": {
"@types/lru-cache": "^5.1.0",
"@types/node": "^14.14.41",
"typescript": "^4.2.4"
},
"dependencies": {
"@sanity/client": "^2.8.0",
"@sanity/uuid": "^3.0.1",
"argon2": "^0.27.2",
"groq": "^2.2.6",
"next-auth": "^4.3.2"
"groq": "^2.2.6"
},
"peerDependencies": {
"@sanity/client": "^5.2.2",
"next-auth": "^4.19.2"
},
"bugs": {
"url": "https://github.com/Fedeya/next-auth-sanity/issues"
Expand Down
14 changes: 9 additions & 5 deletions src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Adapter, AdapterUser } from 'next-auth/adapters';
import type { Adapter } from 'next-auth/adapters';
import {
getUserByIdQuery,
getUserByProviderAccountIdQuery,
Expand Down Expand Up @@ -28,6 +28,7 @@ export function SanityAdapter(

return {
id: _id,
// @ts-ignore
emailVerified: null,
...user
};
Expand Down Expand Up @@ -82,12 +83,15 @@ export function SanityAdapter(
async deleteSession() {},

async updateUser(user) {
const newUser = await client.patch(user.id!).set(user).commit();
const { _id, ...newUser } = await client
.patch(user.id!)
.set(user)
.commit<typeof user>();

return {
id: newUser._id,
...newUser,
emailVerified: null
id: _id,
emailVerified: null,
...(newUser as any)
};
},

Expand Down
9 changes: 5 additions & 4 deletions src/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type { CredentialsProvider } from 'next-auth/providers';
import type { CredentialsConfig } from 'next-auth/providers';
import Credentials from 'next-auth/providers/credentials';
import type { SanityClient } from '@sanity/client';
import { getUserByEmailQuery } from './queries';
import argon2 from 'argon2';
import { uuid } from '@sanity/uuid';

type CredentialsConfig = ReturnType<CredentialsProvider>;

export const signUpHandler =
(client: SanityClient, userSchema: string = 'user') =>
async (req: any, res: any) => {
Expand All @@ -22,6 +19,8 @@ export const signUpHandler =
return;
}

const argon2 = await import('argon2');

const { password: _, ...newUser } = await client.create({
_id: `user.${uuid()}`,
_type: userSchema,
Expand Down Expand Up @@ -62,6 +61,8 @@ export const SanityCredentials = (
email: credentials?.email
});

const argon2 = await import('argon2');

if (!user) throw new Error('Email does not exist');

if (await argon2.verify(user.password, credentials?.password!)) {
Expand Down
23 changes: 10 additions & 13 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"target": "ES2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": ".", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"outDir": "." /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
Expand All @@ -25,7 +25,7 @@
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
Expand All @@ -50,7 +50,7 @@
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

Expand All @@ -65,11 +65,8 @@
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"exclude": [
"./examples",
"./dist"
]
"exclude": ["./examples", "./dist"]
}
Loading

0 comments on commit 40db69f

Please sign in to comment.