4 Replies
Anyone knows how to solve these?
authoptions
import { env } from "@/env.mjs";
import { db } from "@/server/db";
import { PrismaAdapter } from "@auth/prisma-adapter";
import {
getServerSession,
type DefaultSession,
type NextAuthOptions,
} from "next-auth";
import GithubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
import { redirect } from "next/navigation";
declare module "next-auth" {
interface Session {
user: DefaultSession["user"] & {
id: string;
};
}
}
export type AuthSession = {
session: {
user: {
id: string;
name?: string;
email?: string;
image?: string;
};
} | null;
};
export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(db),
callbacks: {
session: ({ session, user }) => {
session.user.id = user.id;
return session;
},
},
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}),
GithubProvider({
clientId: env.GITHUB_CLIENT_ID,
clientSecret: env.GITHUB_CLIENT_SECRET,
}),
],
};
export const getUserAuth = async () => {
const session = await getServerSession(authOptions);
return { session } as AuthSession;
};
export const checkAuth = async () => {
const { session } = await getUserAuth();
if (!session) redirect("/api/auth/signin");
};
changing to these solves the error
but i am not sure if its the right way to do it
it only solves the type error, if i build the project it throws an error