-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authentication, and Database integration (#73)
* Add next auth and drizzleORM dependencies * Configure Next auth and refactor env variables configuration * Add login screen * Get user directly from auth * Add a User profile menu * Run database and collaboration server on dev script * Configure prisma adapter and update collab server schema to match * Add volume to persist development database changes * Add development database URL to public .env file * Add notebooks schema * Let front-end handle Document table creation to prevent inconsistencies * Store author of each document * Create/ delete documents from database directly. Move /:workspaceId/:noteId to /notes Group all authentication routes under (auth) directory Refactor useSelf() and useOthers() to use user directly from auth Remove workspaceId parameter on createItem * Create get document by name action * Make Editor a separate component, and also separate the configuration to its own domain * Store all document types in the same database table. Add "notebookName" parameter to StartCollaboration. Remove useWorkspace. Initialize Sidebar items "id" as empty string * Migrate to drizzle-orm * Remove documentNotebookTable, add notebookId path again * Authorize collaboration server connection using JWTs * Move useSelf and useOthers from userStore to collaboration lib * Pass token value to collaborationPlugin and StartCollaboration * Configure Discord, Google login * remove unnecessary migrations * Add example environment variables * Use nanoid for notebookId * Patch Next.js ESLint warnings * Add missing dependencies * Refactor sign in screen * Generate initial migrations * Drop foreign key constraints * Add notebook to document maping drizzle relations
- Loading branch information
1 parent
2ba7038
commit 0621541
Showing
65 changed files
with
10,912 additions
and
7,007 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
NEXT_PUBLIC_COLLAB_SERVER_URL=ws://localhost:1234 | ||
NEXT_PUBLIC_COLLAB_SERVER_URL=ws://localhost:1234 | ||
|
||
# Local development database | ||
# This should match the same one configured for the collaboration server | ||
DATABASE_URL=mysql://root:pass@localhost/jotter | ||
|
||
|
||
NEXTAUTH_URL=http://localhost:3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Next Auth | ||
NEXTAUTH_SECRET= | ||
|
||
GITHUB_CLIENT_ID= | ||
GITHUB_SECRET= | ||
|
||
GOOGLE_CLIENT_ID= | ||
GOOGLE_SECRET= | ||
|
||
DISCORD_CLIENT_ID= | ||
DISCORD_SECRET= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from "drizzle-kit"; | ||
|
||
export default defineConfig({ | ||
schema: "./src/schema.ts", | ||
driver: "mysql2", | ||
out: "./drizzle", | ||
dbCredentials: { | ||
uri: process.env.DATABASE_URL!, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
CREATE TABLE `account` ( | ||
`userId` varchar(255) NOT NULL, | ||
`type` varchar(255) NOT NULL, | ||
`provider` varchar(255) NOT NULL, | ||
`providerAccountId` varchar(255) NOT NULL, | ||
`refresh_token` varchar(255), | ||
`access_token` varchar(255), | ||
`expires_at` int, | ||
`token_type` varchar(255), | ||
`scope` varchar(255), | ||
`id_token` varchar(2048), | ||
`session_state` varchar(255), | ||
CONSTRAINT `account_provider_providerAccountId_pk` PRIMARY KEY(`provider`,`providerAccountId`) | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `document` ( | ||
`name` char(21) NOT NULL, | ||
`createdOn` timestamp DEFAULT (now()), | ||
`modifiedOn` timestamp DEFAULT (now()), | ||
`data` blob, | ||
CONSTRAINT `document_name` PRIMARY KEY(`name`) | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `notebook` ( | ||
`id` char(21) NOT NULL, | ||
`documentName` char(21) NOT NULL, | ||
`authorId` varchar(255) NOT NULL, | ||
CONSTRAINT `notebook_id` PRIMARY KEY(`id`) | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `session` ( | ||
`sessionToken` varchar(255) NOT NULL, | ||
`userId` varchar(255) NOT NULL, | ||
`expires` timestamp NOT NULL, | ||
CONSTRAINT `session_sessionToken` PRIMARY KEY(`sessionToken`) | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `user` ( | ||
`id` varchar(255) NOT NULL, | ||
`name` varchar(255), | ||
`email` varchar(255), | ||
`emailVerified` timestamp(3) DEFAULT (now()), | ||
`image` varchar(255), | ||
CONSTRAINT `user_id` PRIMARY KEY(`id`) | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `verificationToken` ( | ||
`identifier` varchar(255) NOT NULL, | ||
`token` varchar(255) NOT NULL, | ||
`expires` timestamp NOT NULL, | ||
CONSTRAINT `verificationToken_identifier_token_pk` PRIMARY KEY(`identifier`,`token`) | ||
); | ||
--> statement-breakpoint | ||
ALTER TABLE `account` ADD CONSTRAINT `account_userId_user_id_fk` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint | ||
ALTER TABLE `notebook` ADD CONSTRAINT `notebook_documentName_document_name_fk` FOREIGN KEY (`documentName`) REFERENCES `document`(`name`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint | ||
ALTER TABLE `notebook` ADD CONSTRAINT `notebook_authorId_user_id_fk` FOREIGN KEY (`authorId`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint | ||
ALTER TABLE `session` ADD CONSTRAINT `session_userId_user_id_fk` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ALTER TABLE `account` DROP FOREIGN KEY `account_userId_user_id_fk`; | ||
--> statement-breakpoint | ||
ALTER TABLE `notebook` DROP FOREIGN KEY `notebook_documentName_document_name_fk`; | ||
--> statement-breakpoint | ||
ALTER TABLE `notebook` DROP FOREIGN KEY `notebook_authorId_user_id_fk`; | ||
--> statement-breakpoint | ||
ALTER TABLE `session` DROP FOREIGN KEY `session_userId_user_id_fk`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE `notebook_document` ( | ||
`notebookId` char(21) NOT NULL, | ||
`documentName` char(21) NOT NULL, | ||
CONSTRAINT `notebook_document_notebookId` PRIMARY KEY(`notebookId`) | ||
); | ||
--> statement-breakpoint | ||
ALTER TABLE `document` ADD `id` char(21) NOT NULL;--> statement-breakpoint | ||
ALTER TABLE `notebook` DROP COLUMN `documentName`; |
Oops, something went wrong.