varkaria
varkaria
TTCTheo's Typesafe Cult
Created by varkaria on 9/23/2024 in #questions
"Can't resolve '@node-rs/argon2-wasm32-wasi'" when i tried to add hash logic to auth
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);
};
3 replies