Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@next-auth/dgraph-adapter

Package Overview
Dependencies
Maintainers
4
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@next-auth/dgraph-adapter - npm Package Compare versions

Comparing version 0.2.2-next.293 to 0.2.2-next.300

dist/client.d.ts

7

dist/graphql/fragments.d.ts

@@ -1,3 +0,4 @@

export declare const makeUserFragment: (customFields: string) => string;
export declare const accountFragment = "\n fragment AccountFragment on Account {\n id\n type\n provider\n providerAccountId\n expires_at\n token_type\n scope\n access_token\n refresh_token\n id_token\n session_state\n }\n";
export declare const sessionFragment = "\n fragment SessionFragment on Session {\n expires\n id\n sessionToken\n user {\n id\n name\n email\n }\n }\n";
export declare const User = "\n fragment UserFragment on User {\n email\n id\n image\n name\n emailVerified\n }\n";
export declare const Account = "\n fragment AccountFragment on Account {\n id\n type\n provider\n providerAccountId\n expires_at\n token_type\n scope\n access_token\n refresh_token\n id_token\n session_state\n }\n";
export declare const Session = "\n fragment SessionFragment on Session {\n expires\n id\n sessionToken\n }\n";
export declare const VerificationToken = "\n fragment VerificationTokenFragment on VerificationToken {\n identifier\n token\n expires\n }\n";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sessionFragment = exports.accountFragment = exports.makeUserFragment = void 0;
const makeUserFragment = (customFields) => /* GraphQL */ `
exports.VerificationToken = exports.Session = exports.Account = exports.User = void 0;
exports.User = `
fragment UserFragment on User {

@@ -11,7 +11,5 @@ email

emailVerified
${customFields}
}
`;
exports.makeUserFragment = makeUserFragment;
exports.accountFragment = `
exports.Account = `
fragment AccountFragment on Account {

@@ -31,3 +29,3 @@ id

`;
exports.sessionFragment = `
exports.Session = `
fragment SessionFragment on Session {

@@ -37,8 +35,10 @@ expires

sessionToken
user {
id
name
email
}
}
`;
exports.VerificationToken = `
fragment VerificationTokenFragment on VerificationToken {
identifier
token
expires
}
`;

@@ -0,4 +1,14 @@

import { format } from "./utils";
import type { Adapter } from "next-auth/adapters";
import { DgraphClient } from "./dgraphClient";
export declare function DgraphAdapter(client: DgraphClient): Adapter;
export { DgraphClient };
import type { DgraphClientParams } from "./client";
export type { DgraphClientParams, DgraphClientError } from "./client";
export interface DgraphAdapterOptions {
fragments?: {
User?: string;
Account?: string;
Session?: string;
VerificationToken?: string;
};
}
export { format };
export declare function DgraphAdapter(client: DgraphClientParams, options?: DgraphAdapterOptions): Adapter;

@@ -21,53 +21,115 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DgraphClient = exports.DgraphAdapter = void 0;
const dgraphClient_1 = require("./dgraphClient");
Object.defineProperty(exports, "DgraphClient", { enumerable: true, get: function () { return dgraphClient_1.DgraphClient; } });
const mutations = __importStar(require("./graphql/mutations"));
const queries = __importStar(require("./graphql/queries"));
const format_1 = __importDefault(require("./format"));
function DgraphAdapter(client) {
const { dgraph, userFragment } = client;
exports.DgraphAdapter = exports.format = void 0;
const client_1 = require("./client");
const utils_1 = require("./utils");
Object.defineProperty(exports, "format", { enumerable: true, get: function () { return utils_1.format; } });
const defaultFragments = __importStar(require("./graphql/fragments"));
function DgraphAdapter(client, options) {
const c = (0, client_1.client)(client);
const fragments = { ...defaultFragments, ...options === null || options === void 0 ? void 0 : options.fragments };
return {
// USERS
createUser: async (input) => {
const { user: [newUser], } = await dgraph(mutations.createUser(userFragment), {
input,
});
// console.log("AdapterUser", format<AdapterUser>(newUser))
return (0, format_1.default)(newUser);
async createUser(input) {
const result = await c.run(
/* GraphQL */ `
mutation ($input: [AddUserInput!]!) {
addUser(input: $input) {
user {
...UserFragment
}
}
}
${fragments.User}
`, { input });
return utils_1.format.from(result === null || result === void 0 ? void 0 : result.user[0]);
},
getUser: async (id) => {
const user = await dgraph(queries.getUserById(userFragment), { id });
if (!user)
return null;
return (0, format_1.default)(user);
async getUser(id) {
const result = await c.run(
/* GraphQL */ `
query ($id: ID!) {
getUser(id: $id) {
...UserFragment
}
}
${fragments.User}
`, { id });
return utils_1.format.from(result);
},
getUserByEmail: async (email) => {
const [user] = await dgraph(queries.getUserByEmail(userFragment), {
email,
});
if (!user)
return null;
return (0, format_1.default)(user);
async getUserByEmail(email) {
const [user] = await c.run(
/* GraphQL */ `
query ($email: String = "") {
queryUser(filter: { email: { eq: $email } }) {
...UserFragment
}
}
${fragments.User}
`, { email });
return utils_1.format.from(user);
},
async getUserByAccount(provider_providerAccountId) {
const [account] = await dgraph(queries.getUserByAccount(userFragment), provider_providerAccountId);
if (account === null || account === void 0 ? void 0 : account.user) {
return (0, format_1.default)(account.user);
const [account] = await c.run(
/* GraphQL */ `
query ($providerAccountId: String = "", $provider: String = "") {
queryAccount(
filter: {
and: {
providerAccountId: { eq: $providerAccountId }
provider: { eq: $provider }
}
}
) {
user {
...UserFragment
}
id
}
return null;
}
${fragments.User}
`, provider_providerAccountId);
return utils_1.format.from(account === null || account === void 0 ? void 0 : account.user);
},
updateUser: async ({ id, ...input }) => {
if (!id)
return input;
const { user: [updatedUser], } = await dgraph(mutations.updateUser(userFragment), { id, input });
return updatedUser;
async updateUser({ id, ...input }) {
const result = await c.run(
/* GraphQL */ `
mutation ($id: [ID!] = "", $input: UserPatch) {
updateUser(input: { filter: { id: $id }, set: $input }) {
user {
...UserFragment
}
}
}
${fragments.User}
`, { id, input });
return utils_1.format.from(result.user[0]);
},
deleteUser: async (id) => {
const { user: [deletedUser], } = await dgraph(mutations.deleteUser, { id });
await dgraph(mutations.deleteUserAccountsAndSessions, {
async deleteUser(id) {
const result = await c.run(
/* GraphQL */ `
mutation ($id: [ID!] = "") {
deleteUser(filter: { id: $id }) {
numUids
user {
accounts {
id
}
sessions {
id
}
}
}
}
`, { id });
const deletedUser = utils_1.format.from(result.user[0]);
await c.run(
/* GraphQL */ `
mutation ($accounts: [ID!], $sessions: [ID!]) {
deleteAccount(filter: { id: $accounts }) {
numUids
}
deleteSession(filter: { id: $sessions }) {
numUids
}
}
`, {
sessions: deletedUser.sessions.map((x) => x.id),

@@ -78,22 +140,48 @@ accounts: deletedUser.accounts.map((x) => x.id),

},
// ACCOUNTS
linkAccount: async ({ userId, ...rest }) => {
const account = await dgraph(mutations.linkAccount, {
input: {
...rest,
user: {
id: userId,
},
},
});
return (0, format_1.default)(account);
async linkAccount(data) {
const { userId, ...input } = data;
await c.run(
/* GraphQL */ `
mutation ($input: [AddAccountInput!]!) {
addAccount(input: $input) {
account {
...AccountFragment
}
}
}
${fragments.Account}
`, { input: { ...input, user: { id: userId } } });
return data;
},
unlinkAccount: async (provider_providerAccountId) => {
return await dgraph(mutations.unlinkAccount, provider_providerAccountId);
async unlinkAccount(provider_providerAccountId) {
await c.run(
/* GraphQL */ `
mutation ($providerAccountId: String = "", $provider: String = "") {
deleteAccount(
filter: {
and: {
providerAccountId: { eq: $providerAccountId }
provider: { eq: $provider }
}
}
) {
numUids
}
}
`, provider_providerAccountId);
},
// SESSIONS
async getSessionAndUser(sessionToken) {
const [sessionAndUser] = await dgraph(queries.getSession(userFragment), {
sessionToken,
});
const [sessionAndUser] = await c.run(
/* GraphQL */ `
query ($sessionToken: String = "") {
querySession(filter: { sessionToken: { eq: $sessionToken } }) {
...SessionFragment
user {
...UserFragment
}
}
}
${fragments.User}
${fragments.Session}
`, { sessionToken });
if (!sessionAndUser)

@@ -103,51 +191,88 @@ return null;

return {
user: (0, format_1.default)(user),
session: {
...(0, format_1.default)(session),
userId: (user === null || user === void 0 ? void 0 : user.id) || null,
},
user: utils_1.format.from(user),
session: { ...utils_1.format.from(session), userId: user.id },
};
},
createSession: async ({ userId, sessionToken, expires }) => {
const { session: [newSession], } = await dgraph(mutations.addSession, {
input: {
sessionToken,
expires,
user: {
id: userId,
},
},
});
return {
...(0, format_1.default)(newSession),
userId: newSession.user.id,
};
async createSession(data) {
const { userId, ...input } = data;
await c.run(
/* GraphQL */ `
mutation ($input: [AddSessionInput!]!) {
addSession(input: $input) {
session {
...SessionFragment
}
}
}
${fragments.Session}
`, { input: { ...input, user: { id: userId } } });
return data;
},
updateSession: async ({ sessionToken, ...input }) => {
const { session: [updatedSession], } = await dgraph(mutations.updateSession, {
sessionToken,
input,
});
if (!updatedSession)
async updateSession({ sessionToken, ...input }) {
var _a;
const result = await c.run(
/* GraphQL */ `
mutation ($input: SessionPatch = {}, $sessionToken: String) {
updateSession(
input: {
filter: { sessionToken: { eq: $sessionToken } }
set: $input
}
) {
session {
...SessionFragment
user {
id
}
}
}
}
${fragments.Session}
`, { sessionToken, input });
const session = utils_1.format.from(result.session[0]);
if (!((_a = session === null || session === void 0 ? void 0 : session.user) === null || _a === void 0 ? void 0 : _a.id))
return null;
return { ...updatedSession, userId: updatedSession.user.id };
return { ...session, userId: session.user.id };
},
deleteSession: async (sessionToken) => await dgraph(mutations.deleteSession, { sessionToken }),
// TOKENS
createVerificationToken: async (input) => {
return await dgraph(mutations.createVerificationRequest, {
input,
});
async deleteSession(sessionToken) {
await c.run(
/* GraphQL */ `
mutation ($sessionToken: String = "") {
deleteSession(filter: { sessionToken: { eq: $sessionToken } }) {
numUids
}
}
`, { sessionToken });
},
useVerificationToken: async ({ identifier, token }) => {
const { verificationRequest: [request], } = await dgraph(mutations.deleteVerificationRequest, {
identifier,
token,
});
if (!request)
return null;
return (0, format_1.default)(request);
async createVerificationToken(input) {
const result = await c.run(
/* GraphQL */ `
mutation ($input: [AddVerificationTokenInput!]!) {
addVerificationToken(input: $input) {
numUids
}
}
`, { input });
return utils_1.format.from(result);
},
async useVerificationToken(params) {
const result = await c.run(
/* GraphQL */ `
mutation ($token: String = "", $identifier: String = "") {
deleteVerificationToken(
filter: {
and: { token: { eq: $token }, identifier: { eq: $identifier } }
}
) {
verificationToken {
...VerificationTokenFragment
}
}
}
${fragments.VerificationToken}
`, params);
return utils_1.format.from(result.verificationToken[0]);
},
};
}
exports.DgraphAdapter = DgraphAdapter;
{
"name": "@next-auth/dgraph-adapter",
"version": "0.2.2-next.293+c961462",
"version": "0.2.2-next.300+8130b6c",
"description": "Dgraph adapter for next-auth.",

@@ -30,3 +30,3 @@ "homepage": "https://next-auth.js.org",

"build": "tsc",
"test": "jest"
"test": "./tests/test.sh"
},

@@ -48,3 +48,3 @@ "peerDependencies": {

},
"gitHead": "c961462e45318af9489a3763f62c5c8ad3445752"
"gitHead": "8130b6c341758377f09dab5bad4943939aab7ec6"
}

@@ -36,14 +36,4 @@ <p align="center">

import NextAuth from "next-auth"
import { DgraphClient, DgraphAdapter } from "@next-auth/dgraph-adapter/dgraphAdapter";
import { DgraphAdapter } from "@next-auth/dgraph-adapter";
const dgraph = new DgraphClient({
endpoint: process.env.DGRAPH_GRAPHQL_ENDPOINT,
apiKey: process.env.DGRAPH_GRAPHQL_KEY,
// you can omit the following properties if you are running an unsecure schema
authHeader: "<YOUR AUTH HEADER>",
jwtSecret: process.env.SECRET
});
// For more information on each option (and a full list of options) go to

@@ -56,3 +46,10 @@ // https://next-auth.js.org/configuration/options

],
adapter: DgraphAdapter(dgraph)
adapter: DgraphAdapter({
endpoint: process.env.DGRAPH_GRAPHQL_ENDPOINT,
authToken: process.env.DGRAPH_GRAPHQL_KEY,
// you can omit the following properties if you are running an unsecure schema
authHeader: "<YOUR AUTH HEADER>",
jwtSecret: process.env.SECRET
})
...

@@ -59,0 +56,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc