Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // @ts-nocheck
- // 'PostgresError: relation "session" does not exist
- //yeah ok, but the session will be null ? it shouldnt but gives this error either when we tried on the home page, session is null
- // 0) Learn next-auth or clerk
- // 1) If none of them works, try Clerk (so i'll rebuild my whole system) no actually its working like nextauth, only for auth part.
- //okay, i'll look at that, thanks for all sorry, but at least we fixed all errors yeah :D, good night and thanks :) bye then :)
- import { DrizzleAdapter } from "@auth/drizzle-adapter"
- import {
- type DefaultSession,
- getServerSession,
- type NextAuthOptions,
- } from "next-auth";
- import DiscordProvider from "next-auth/providers/discord";
- import { db } from "@/server/db/";
- import { users } from "@/server/db/schema";
- import { eq } from "drizzle-orm";
- import GoogleProvider from "next-auth/providers/google";
- import { env } from "@/env.mjs";
- import CredentialsProvider from "next-auth/providers/credentials";
- import { signInSchema } from "@/schema/authSchema";
- import { verify } from "argon2";
- //it can be there n
- declare module "next-auth" {
- interface Session extends DefaultSession {
- user: {
- id: string;
- isStaff: boolean
- } & DefaultSession["user"];
- }
- interface User {
- // ...other properties
- isStaff: boolean
- }
- }
- // ! Are you seeing that a lot errors, or just i am
- //I'm seeing them, but on webstorm it's not like that, I think the compilator is not the same
- // use vscode :D,
- // in fact webstorm offer more options
- // in errors like user[0]... is because I removed checks, yep. i ll look at that, thats why i said remove checks okay :D
- // First, are you using latest version of nextauth yeah,
- // latest version ; 4.24.3
- export const authOptions: NextAuthOptions = {
- callbacks: {
- jwt({ token, user }) {
- // user &&
- // console.log({ "user": user, "token": token });
- // are you sure about here
- //it worked before lol, we can try to remove token = and see what happen, rabbit holes :D
- // I would say your auth declarations are totally wrong
- //Maybe, I don't use nextauth usually (idk if its english), I'm on AdonisJS, but I tried nextauth lol
- /**
- * Type '({ session, token }: { session: Session; token: JWT; user: AdapterUser; } & { newSession: any; trigger: "update"; }) => Promise<{ name: string | null; surname: string | null; id: string; email: string; delivery: { ...; }; }>' is not assignable to type '(params: { session: Session; token: JWT; user: AdapterUser; } & { newSession: any; trigger: "update"; }) => Awaitable<DefaultSession | Session>'.
- */
- return token;
- },
- // dont think you need a session
- //I think I need, because TRPC needs too with the context (ctx.session.user.id......) wait a sec
- // async session() {
- // const user = await db.select().from(users).where(eq(users.email, token.email))
- // console.log("user2", user)
- // // if (!user ) {
- // // return null;
- // // }
- // return {
- // name: user[0].name,
- // surname: user[0].surname,
- // id: user[0].id,
- // email: user[0].email,
- // delivery: {
- // city: user[0].city,
- // address: user[0].address,
- // postal_code: user[0].postal_code
- // },
- // }
- // },
- async session({ session, token }) {
- const user = await db.select().from(users).where(eq(users.email, token.email!))
- console.log("user2", user)
- session.user.id = token.id as string
- //i'll go to sleep (check discord) look at line 1, then you can go for sure
- return session
- }
- },
- pages: {
- //signOut: '/api/auth/signout',
- newUser: "/api/auth/register"
- },
- //this code if very like 'if it works, don't touch it' lol (the whole nextauth part)
- // If you use an `adapter` however, we default it to `"database"` instead.
- // relation "session" does not exist PostgresError: relation "session" does not exist
- /**
- * now run app again while studio working, before wait for me.
- * "scripts": {
- "build": "next build",
- "db:push": "dotenv drizzle-kit push:pg", [2]
- "db:generate": "dotenv drizzle-kit generate:pg", [1]
- "db:studio": "dotenv drizzle-kit studio", [3]
- "dev": "next dev", [4]
- "lint": "next lint",
- "start": "next start"
- I should drop the table I think ,do you have seed, seed ? when you run app will it fill DB, no, but the registration process is fast, ok then its best, first kill all terminals
- },
- */
- jwt: {
- // maxAge: 60 * 60 * 24 * 30 * 6,
- maxAge: 60 * 60 * 24 * 30,
- },
- secret: env.NEXTAUTH_SECRET,
- // Here gives error ! (I'm following you, yea but gives error :D , but why? even it says docs as is)
- // adapter: DrizzleAdapter(db, pgTable),
- // import { db } from "./schema", but in your schema and at docs, there is nothing like db. Db is in
- /**
- * ?says that: yeah I saw, @[email protected], [email protected] [If you can ignore this error at runtime, its okay.]
- * Like with a ts-ignore ? (yeah ok)
- * Why did you move db to schema ?, at example it was saying, no matter you can revert it tho.
- * Yeah because every component use db, so import are fucked up now ^^
- * Type 'import("/Users/alexisdumain/development/web/shoptongout.fr/node_modules/.pnpm/@[email protected]/node_modules/@auth/core/adapters").Adapter' is not assignable to type 'import("/Users/alexisdumain/development/web/shoptongout.fr/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/adapters").Adapter'.
- Types of property 'createUser' are incompatible.
- You want me to try ? [fingers crossed , at least there is no error now]
- Do you see console errors ?, can you clear and rerun again. Do you see my terminal? yea
- Can we try that ?
- pnpm add drizzle-orm @auth/drizzle-adapter
- pnpm add drizzle-kit --save-dev, havent you Idk, I think so, but it'll update.? I yep pnpm is yours
- f1 > restart TS server, you know what, probably two libs conflicting. Maybe, but how can we know ? remove modules. Okay i'll try
- `rm -rf node_modules, remove pnpm cache, how ? wait i'll search pnpm store prune? I'll try it ?, wait.
- `remove .lock file, remove node_modules, remove cache`I think it's good?, its reading that .lock to install pkgs mhh? I removed it (pnpm-lock) okay above ok ? yeah, now wait.
- we can try b
- y using npm? wait . so ? :D. We have the error, but the cookie is well written in the app
- // could it related with jwt expire
- But, the error indicate that relation "session" does not exist PostgresError: relation "session" does not exist, it's maybe related to schema ? either schema or db, do you know dealing with migrations. A little bit lol
- ALTER TABLE "shoptongout_product" ALTER COLUMN "remaining_quantity" DROP DEFAULT;
- can you undo latest migration which makes this yeah, but I should just remove the drizzle folder, drop the tables, and try again, if you dont have a data to lose
- "db:push": "dotenv drizzle-kit push:pg", [2]
- "db:generate": "dotenv drizzle-kit generate:pg", [1] <<
- "db:studio": "dotenv drizzle-kit studio", [3]
- "dev": "next dev", [4]
- DONE
- mhh, we have the user in console, but when I want to access to my privates page, i get unauthorized, s
- ession token is not stored too
- have you made 1,2,3,4 as follows yeep, can you see your data at studio yeah so DB works, yeah the registration process works, even in the console we can see that it returns the good data, and
- email: '[email protected]',
- password: '$argon2id$v=1'
- its because the session is not stored in database, but the user yes. Do i really need a session ? lol
- ah yes, cuz you provided it in here yeah ok, but the session seems to work ? we get the good data
- SESSION: null
- */
- adapter: DrizzleAdapter(db),
- providers: [
- DiscordProvider({
- clientId: env.DISCORD_CLIENT_ID,
- clientSecret: env.DISCORD_CLIENT_SECRET,
- }),
- GoogleProvider({
- clientId: env.GOOGLE_CLIENT_ID,
- clientSecret: env.GOOGLE_CLIENT_SECRET
- }),
- CredentialsProvider({
- name: "credentials",
- credentials: {
- username: { label: "Username", type: "text", placeholder: "jsmith" },
- password: { label: "Password", type: "password" }
- },
- authorize: async (credentials) => {
- const creds = await signInSchema.parseAsync(credentials);
- const user = await db.select().from(users).where(eq(users.email, creds.email));
- // console.log("user3: ", user[0])
- if (user[0]) {
- const isValidPassword = await verify(user[0].password!, creds.password);
- if (!isValidPassword) {
- return null;
- }
- return user[0]
- // return {
- // user: {
- // name: user[0].name,
- // surname: user[0].surname,
- // id: user[0].id,
- // email: user[0].email,
- // isStaff: user[0].isStaff,
- // delivery: {
- // city: user[0].city,
- // address: user[0].address,
- // postal_code: user[0].postal_code
- // },
- // }
- // }
- }
- return null;
- },
- type: "credentials"
- }),
- ],
- };
- export const getServerAuthSession = () => getServerSession(authOptions);
Add Comment
Please, Sign In to add comment