Skip to content

Commit

Permalink
Merge pull request #22 from SteakFisher/auth-n-auth
Browse files Browse the repository at this point in the history
Finished authentication
  • Loading branch information
SteakFisher authored Jun 14, 2024
2 parents a82f65c + 76d4219 commit 9f1b2d0
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 66 deletions.
71 changes: 70 additions & 1 deletion drizzle/schema.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import type { AdapterAccountType } from "next-auth/adapters";
import FormItem from "@/interfaces/FormItem";
import {
index,
integer,
sqliteTable,
text,
uniqueIndex,
primaryKey,
} from "drizzle-orm/sqlite-core";

export const formsTable = sqliteTable(
"forms",
{
formId: text("formId").primaryKey(),
userId: text("userId").notNull(),
formJson: text("formJson", { mode: "json" }).notNull().$type<FormItem[]>(),
formJson: text("formJson", { mode: "json" })
.notNull()
.$type<FormItem[]>(),
version: integer("version", { mode: "number" }).notNull(),
},
(table) => {
Expand All @@ -22,3 +26,68 @@ export const formsTable = sqliteTable(
};
},
);

export const users = sqliteTable("user", {
id: text("id")
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
name: text("name"),
email: text("email").notNull(),
emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
image: text("image"),
});

export const accounts = sqliteTable(
"account",
{
userId: text("userId")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
type: text("type").$type<AdapterAccountType>().notNull(),
provider: text("provider").notNull(),
providerAccountId: text("providerAccountId").notNull(),
refresh_token: text("refresh_token"),
access_token: text("access_token"),
expires_at: integer("expires_at"),
token_type: text("token_type"),
scope: text("scope"),
id_token: text("id_token"),
session_state: text("session_state"),
},
(account) => ({
compoundKey: primaryKey({
columns: [account.provider, account.providerAccountId],
}),
}),
);

export const sessions = sqliteTable("session", {
sessionToken: text("sessionToken").primaryKey(),
userId: text("userId")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
});

export const authenticators = sqliteTable(
"authenticator",
{
credentialID: text("credentialID").notNull().unique(),
userId: text("userId")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
providerAccountId: text("providerAccountId").notNull(),
credentialPublicKey: text("credentialPublicKey").notNull(),
counter: integer("counter").notNull(),
credentialDeviceType: text("credentialDeviceType").notNull(),
credentialBackedUp: integer("credentialBackedUp", {
mode: "boolean",
}).notNull(),
transports: text("transports"),
},
(authenticator) => ({
compositePK: primaryKey({
columns: [authenticator.userId, authenticator.credentialID],
}),
}),
);
144 changes: 87 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"firebase-admin": "^12.1.1",
"get-video-id": "^4.1.5",
"lucide-react": "^0.364.0",
"next": "^14.2.3",
"next":"14.1.0",
"next-auth": "^5.0.0-beta.19",
"next-themes": "^0.2.1",
"react": "^18",
"react-animate-height": "^3.2.3",
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { handlers } from "@/helpers/auth"; // Referring to the auth.ts we just created
export const { GET, POST } = handlers;
Loading

0 comments on commit 9f1b2d0

Please sign in to comment.