"Can't resolve '@node-rs/argon2-wasm32-wasi'" when i tried to add hash logic to auth

I created with t3 stack turbo from julius add i need to add cridential provider to auth packages and it will have hash logic to check password. i using @node-rs/argon2 for verify that after i imported and testing it show this error so. is it have any example of t3 stack turbo with cridentials user name password project to learn that?
No description
1 Reply
varkaria
varkariaOP3mo ago
import type {
DefaultSession,
NextAuthConfig,
Session as NextAuthSession,
} from "next-auth";
import { skipCSRFCheck } from "@auth/core";
import { PrismaAdapter } from "@auth/prisma-adapter";

import Discord from "next-auth/providers/discord";
import Credentials from "next-auth/providers/credentials"

import { db } from "@app/db";
import { env } from "../env";
import { verify } from "@node-rs/argon2";

declare module "next-auth" {
interface Session {
user: {
id: string;
} & DefaultSession["user"];
}
}

const adapter = PrismaAdapter(db);

export const isSecureContext = env.NODE_ENV !== "development";

export const authConfig = {
adapter,
// In development, we need to skip checks to allow Expo to work
...(!isSecureContext
? {
skipCSRFCheck: skipCSRFCheck,
trustHost: true,
}
: {}),
secret: env.AUTH_SECRET,
providers: [
Discord,
Credentials({
// You can specify which fields should be submitted, by adding keys to the `credentials` object.
// e.g. domain, username, password, 2FA token, etc.
credentials: {
email: {},
password: {},
},
authorize: async () => {
// Testing add hash logic here
await verify('TEST', 'TEST');

return {}
},
}),],
callbacks: {
session: (opts) => {
if (!("user" in opts))
throw new Error("unreachable with session strategy");

return {
...opts.session,
user: {
...opts.session.user,
id: opts.user.id,
},
};
},
},
} satisfies NextAuthConfig;

export const validateToken = async (
token: string,
): Promise<NextAuthSession | null> => {
const sessionToken = token.slice("Bearer ".length);
const session = await adapter.getSessionAndUser?.(sessionToken);
return session
? {
user: {
...session.user,
},
expires: session.session.expires.toISOString(),
}
: null;
};

export const invalidateSessionToken = async (token: string) => {
const sessionToken = token.slice("Bearer ".length);
await adapter.deleteSession?.(sessionToken);
};
import type {
DefaultSession,
NextAuthConfig,
Session as NextAuthSession,
} from "next-auth";
import { skipCSRFCheck } from "@auth/core";
import { PrismaAdapter } from "@auth/prisma-adapter";

import Discord from "next-auth/providers/discord";
import Credentials from "next-auth/providers/credentials"

import { db } from "@app/db";
import { env } from "../env";
import { verify } from "@node-rs/argon2";

declare module "next-auth" {
interface Session {
user: {
id: string;
} & DefaultSession["user"];
}
}

const adapter = PrismaAdapter(db);

export const isSecureContext = env.NODE_ENV !== "development";

export const authConfig = {
adapter,
// In development, we need to skip checks to allow Expo to work
...(!isSecureContext
? {
skipCSRFCheck: skipCSRFCheck,
trustHost: true,
}
: {}),
secret: env.AUTH_SECRET,
providers: [
Discord,
Credentials({
// You can specify which fields should be submitted, by adding keys to the `credentials` object.
// e.g. domain, username, password, 2FA token, etc.
credentials: {
email: {},
password: {},
},
authorize: async () => {
// Testing add hash logic here
await verify('TEST', 'TEST');

return {}
},
}),],
callbacks: {
session: (opts) => {
if (!("user" in opts))
throw new Error("unreachable with session strategy");

return {
...opts.session,
user: {
...opts.session.user,
id: opts.user.id,
},
};
},
},
} satisfies NextAuthConfig;

export const validateToken = async (
token: string,
): Promise<NextAuthSession | null> => {
const sessionToken = token.slice("Bearer ".length);
const session = await adapter.getSessionAndUser?.(sessionToken);
return session
? {
user: {
...session.user,
},
expires: session.session.expires.toISOString(),
}
: null;
};

export const invalidateSessionToken = async (token: string) => {
const sessionToken = token.slice("Bearer ".length);
await adapter.deleteSession?.(sessionToken);
};
Want results from more Discord servers?
Add your server