fixed schema for authorize

This commit is contained in:
ImAlpha 2023-12-07 22:49:15 -08:00
parent 91c79ed6b9
commit e160eb676c
5 changed files with 81 additions and 80 deletions

View File

@ -43,7 +43,7 @@ const handler = NextAuth({
console.log({ passwordCheck }); console.log({ passwordCheck });
if (passwordCheck) { if (passwordCheck) {
return users; return response[0];
} }
return null; return null;
}, },

View File

@ -1,23 +1,24 @@
// db/schema.ts // db/schema.ts
// pnpm drizzle-kit generate:mysql // pnpm drizzle-kit generate:mysql
// pnpm tsx db/migrate.ts // pnpm tsx db/migrate.ts
// import { import {
// index, index,
// int, int,
// mysqlTable, mysqlTable,
// bigint, bigint,
// varchar, varchar,
// timestamp, timestamp,
// mysqlSchema, mysqlSchema,
// } from "drizzle-orm/mysql-core"; } from "drizzle-orm/mysql-core";
// export const mySchema = mysqlSchema("drizzle_jefes") for creating a new db // export const mySchema = mysqlSchema("drizzle_jefes") for creating a new db
// export const users = mysqlTable("users", { export const users = mysqlTable("users", {
// id: int("id").primaryKey().autoincrement(), // id: int("id").primaryKey().autoincrement(),
// email: varchar("email", { length: 256 }).notNull(), id: varchar("id", { length: 255 }).notNull().primaryKey(),
// password: varchar("password", { length: 256 }).notNull(), email: varchar("email", { length: 256 }).notNull(),
// }); password: varchar("password", { length: 256 }).notNull(),
});
// export const menuItems = mysqlTable("menu_item", { // export const menuItems = mysqlTable("menu_item", {
// id: bigint("id", { mode: "number" }).primaryKey().autoincrement(), // id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
@ -25,66 +26,66 @@
// itemDescription: varchar("item_description", { length: 256 }), // itemDescription: varchar("item_description", { length: 256 }),
// }); // });
import { // import {
int, // int,
timestamp, // timestamp,
mysqlTable, // mysqlTable,
primaryKey, // primaryKey,
varchar, // varchar,
} from "drizzle-orm/mysql-core"; // } from "drizzle-orm/mysql-core";
import type { AdapterAccount } from "@auth/core/adapters"; // import type { AdapterAccount } from "@auth/core/adapters";
export const users = mysqlTable("user", { // export const users = mysqlTable("user", {
id: varchar("id", { length: 255 }).notNull().primaryKey(), // id: varchar("id", { length: 255 }).notNull().primaryKey(),
name: varchar("name", { length: 255 }), // name: varchar("name", { length: 255 }),
email: varchar("email", { length: 255 }).notNull(), // email: varchar("email", { length: 255 }).notNull(),
emailVerified: timestamp("emailVerified", { // emailVerified: timestamp("emailVerified", {
mode: "date", // mode: "date",
fsp: 3, // fsp: 3,
}).defaultNow(), // }).defaultNow(),
image: varchar("image", { length: 255 }), // image: varchar("image", { length: 255 }),
}); // });
export const accounts = mysqlTable( // export const accounts = mysqlTable(
"account", // "account",
{ // {
userId: varchar("userId", { length: 255 }) // userId: varchar("userId", { length: 255 })
.notNull() // .notNull()
.references(() => users.id, { onDelete: "cascade" }), // .references(() => users.id, { onDelete: "cascade" }),
type: varchar("type", { length: 255 }) // type: varchar("type", { length: 255 })
.$type<AdapterAccount["type"]>() // .$type<AdapterAccount["type"]>()
.notNull(), // .notNull(),
provider: varchar("provider", { length: 255 }).notNull(), // provider: varchar("provider", { length: 255 }).notNull(),
providerAccountId: varchar("providerAccountId", { length: 255 }).notNull(), // providerAccountId: varchar("providerAccountId", { length: 255 }).notNull(),
refresh_token: varchar("refresh_token", { length: 255 }), // refresh_token: varchar("refresh_token", { length: 255 }),
access_token: varchar("access_token", { length: 255 }), // access_token: varchar("access_token", { length: 255 }),
expires_at: int("expires_at"), // expires_at: int("expires_at"),
token_type: varchar("token_type", { length: 255 }), // token_type: varchar("token_type", { length: 255 }),
scope: varchar("scope", { length: 255 }), // scope: varchar("scope", { length: 255 }),
id_token: varchar("id_token", { length: 2048 }), // id_token: varchar("id_token", { length: 2048 }),
session_state: varchar("session_state", { length: 255 }), // session_state: varchar("session_state", { length: 255 }),
}, // },
(account) => ({ // (account) => ({
compoundKey: primaryKey(account.provider, account.providerAccountId), // compoundKey: primaryKey(account.provider, account.providerAccountId),
}) // })
); // );
export const sessions = mysqlTable("session", { // export const sessions = mysqlTable("session", {
sessionToken: varchar("sessionToken", { length: 255 }).notNull().primaryKey(), // sessionToken: varchar("sessionToken", { length: 255 }).notNull().primaryKey(),
userId: varchar("userId", { length: 255 }) // userId: varchar("userId", { length: 255 })
.notNull() // .notNull()
.references(() => users.id, { onDelete: "cascade" }), // .references(() => users.id, { onDelete: "cascade" }),
expires: timestamp("expires", { mode: "date" }).notNull(), // expires: timestamp("expires", { mode: "date" }).notNull(),
}); // });
export const verificationTokens = mysqlTable( // export const verificationTokens = mysqlTable(
"verificationToken", // "verificationToken",
{ // {
identifier: varchar("identifier", { length: 255 }).notNull(), // identifier: varchar("identifier", { length: 255 }).notNull(),
token: varchar("token", { length: 255 }).notNull(), // token: varchar("token", { length: 255 }).notNull(),
expires: timestamp("expires", { mode: "date" }).notNull(), // expires: timestamp("expires", { mode: "date" }).notNull(),
}, // },
(vt) => ({ // (vt) => ({
compoundKey: primaryKey(vt.identifier, vt.token), // compoundKey: primaryKey(vt.identifier, vt.token),
}) // })
); // );

View File

@ -1,5 +1,5 @@
CREATE TABLE `users` ( CREATE TABLE `users` (
`id` int AUTO_INCREMENT NOT NULL, `id` varchar(255) NOT NULL,
`email` varchar(256) NOT NULL, `email` varchar(256) NOT NULL,
`password` varchar(256) NOT NULL, `password` varchar(256) NOT NULL,
CONSTRAINT `users_id` PRIMARY KEY(`id`) CONSTRAINT `users_id` PRIMARY KEY(`id`)

View File

@ -1,7 +1,7 @@
{ {
"version": "5", "version": "5",
"dialect": "mysql", "dialect": "mysql",
"id": "9e600bcf-c5c3-4ba9-9a1f-0d981d718812", "id": "d0040233-edf3-434f-baa4-d49255b2e089",
"prevId": "00000000-0000-0000-0000-000000000000", "prevId": "00000000-0000-0000-0000-000000000000",
"tables": { "tables": {
"users": { "users": {
@ -9,10 +9,10 @@
"columns": { "columns": {
"id": { "id": {
"name": "id", "name": "id",
"type": "int", "type": "varchar(255)",
"primaryKey": false, "primaryKey": false,
"notNull": true, "notNull": true,
"autoincrement": true "autoincrement": false
}, },
"email": { "email": {
"name": "email", "name": "email",

View File

@ -5,8 +5,8 @@
{ {
"idx": 0, "idx": 0,
"version": "5", "version": "5",
"when": 1702012909346, "when": 1702017992075,
"tag": "0000_charming_silhouette", "tag": "0000_acoustic_kitty_pryde",
"breakpoints": true "breakpoints": true
} }
] ]