z
z
Explore posts from servers
TTCTheo's Typesafe Cult
Created by z on 6/26/2023 in #questions
NextJS "Module not found" error with "loading.tsx"?
13 replies
TTCTheo's Typesafe Cult
Created by z on 6/10/2023 in #questions
Uploadthing + NextJS (App Dir) API Loop Bug
As shown in the video, i dont think there much else to say...
19 replies
TTCTheo's Typesafe Cult
Created by z on 6/1/2023 in #questions
NextJS and Bare Metal
What all features would break/may not work if I decide to deploy to NEXTjs to bare metal instead of serverless?
5 replies
TTCTheo's Typesafe Cult
Created by z on 5/6/2023 in #questions
Server Actions and tRPC
Is server actions a replacement for tRPC? Or am I just fundamentally wrong about server actions and they have nothing to do with each other?
3 replies
TTCTheo's Typesafe Cult
Created by z on 3/29/2023 in #questions
Modifying 'Session' in next-auth
Code (I removed imports and comments as they are not required):
declare module "next-auth" {
interface Session {
user: {
id: string;
username: string;
password: string;
};
}

interface User {
id: string;
username: string;
password: string;
}
}

export const authOptions: NextAuthOptions = {
session: {
strategy: "jwt",
},
callbacks: {
session({ session, token }) {
console.log("session", session)
console.log("token", token)
if (token && session.user) {
session.user.id = token.id as string;
}

return session;
},
jwt: async ({ token, user }) => {
console.log("user", user)
if (user) {
token.id = user.id;
}

return token;
},
},
// adapter: PrismaAdapter(prisma),
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
username: { label: "Username", type: "text", placeholder: "admin" },
password: { label: "Password", type: "password" }
},
authorize(credentials) {
console.log(credentials)
const {username, password} = credentials
if (username !== "admin" || password !== "admin") {
throw new Error("invalid credentials");
}
const user = {
id: "1234",
username: "admin",
password: "admin",
}
return user
},
}),
],
};

/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*
* @see https://next-auth.js.org/configuration/nextjs
*/
export const getServerAuthSession = (ctx: {
req: GetServerSidePropsContext["req"];
res: GetServerSidePropsContext["res"];
}) => {
return getServerSession(ctx.req, ctx.res, authOptions);
};
declare module "next-auth" {
interface Session {
user: {
id: string;
username: string;
password: string;
};
}

interface User {
id: string;
username: string;
password: string;
}
}

export const authOptions: NextAuthOptions = {
session: {
strategy: "jwt",
},
callbacks: {
session({ session, token }) {
console.log("session", session)
console.log("token", token)
if (token && session.user) {
session.user.id = token.id as string;
}

return session;
},
jwt: async ({ token, user }) => {
console.log("user", user)
if (user) {
token.id = user.id;
}

return token;
},
},
// adapter: PrismaAdapter(prisma),
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
username: { label: "Username", type: "text", placeholder: "admin" },
password: { label: "Password", type: "password" }
},
authorize(credentials) {
console.log(credentials)
const {username, password} = credentials
if (username !== "admin" || password !== "admin") {
throw new Error("invalid credentials");
}
const user = {
id: "1234",
username: "admin",
password: "admin",
}
return user
},
}),
],
};

/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*
* @see https://next-auth.js.org/configuration/nextjs
*/
export const getServerAuthSession = (ctx: {
req: GetServerSidePropsContext["req"];
res: GetServerSidePropsContext["res"];
}) => {
return getServerSession(ctx.req, ctx.res, authOptions);
};
4 replies
TTCTheo's Typesafe Cult
Created by z on 3/7/2023 in #questions
When to use next-auth
If I only plan on only using credentials i.e not using providers like discord, github, etc. Is it worth using next-auth or am I better of making my own custom authentication?
8 replies