Skip to content

Commit

Permalink
Merge pull request #22 from cmgriffing/feat/login-signup
Browse files Browse the repository at this point in the history
feat: add pages and endpoints for login and signup
  • Loading branch information
cmgriffing authored Oct 22, 2024
2 parents 8a45b84 + a7a97f3 commit a61d912
Show file tree
Hide file tree
Showing 26 changed files with 1,343 additions and 32 deletions.
6 changes: 0 additions & 6 deletions packages/shiki-magic-move/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,5 @@
"vitest": "^2.1.1",
"vue": "^3.5.10",
"vue-tsc": "^2.1.6"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
}
}
2 changes: 2 additions & 0 deletions playgrounds/app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ gitignore
# System Files
.DS_Store
Thumbs.db

src/db/local.db
13 changes: 13 additions & 0 deletions playgrounds/app/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require('dotenv').config()

import type { Config } from 'drizzle-kit'

export default {
schema: './src/db/schema.ts',
out: './migrations',
dialect: 'turso',
dbCredentials: {
url: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN || 'foo',
},
} satisfies Config
24 changes: 24 additions & 0 deletions playgrounds/app/migrations/0000_last_patch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE TABLE `snippets_table` (
`id` text PRIMARY KEY NOT NULL,
`userId` text NOT NULL,
`title` text NOT NULL,
`codeLeft` text NOT NULL,
`codeRight` text NOT NULL,
`createdAt` integer DEFAULT 0 NOT NULL,
`updatedAt` integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
CREATE TABLE `users_table` (
`id` text PRIMARY KEY NOT NULL,
`email` text NOT NULL,
`githubId` text NOT NULL,
`githubUsername` text NOT NULL,
`githubAvatarUrl` text NOT NULL,
`createdAt` integer DEFAULT 0 NOT NULL,
`updatedAt` integer DEFAULT 0 NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `users_table_email_unique` ON `users_table` (`email`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_table_githubId_unique` ON `users_table` (`githubId`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_table_githubUsername_unique` ON `users_table` (`githubUsername`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_table_githubAvatarUrl_unique` ON `users_table` (`githubAvatarUrl`);
169 changes: 169 additions & 0 deletions playgrounds/app/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"version": "6",
"dialect": "sqlite",
"id": "05492c90-59bd-45e4-99e5-29a29eb2d4ef",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"snippets_table": {
"name": "snippets_table",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"userId": {
"name": "userId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"codeLeft": {
"name": "codeLeft",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"codeRight": {
"name": "codeRight",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"updatedAt": {
"name": "updatedAt",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"users_table": {
"name": "users_table",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"githubId": {
"name": "githubId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"githubUsername": {
"name": "githubUsername",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"githubAvatarUrl": {
"name": "githubAvatarUrl",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"updatedAt": {
"name": "updatedAt",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
}
},
"indexes": {
"users_table_email_unique": {
"name": "users_table_email_unique",
"columns": [
"email"
],
"isUnique": true
},
"users_table_githubId_unique": {
"name": "users_table_githubId_unique",
"columns": [
"githubId"
],
"isUnique": true
},
"users_table_githubUsername_unique": {
"name": "users_table_githubUsername_unique",
"columns": [
"githubUsername"
],
"isUnique": true
},
"users_table_githubAvatarUrl_unique": {
"name": "users_table_githubAvatarUrl_unique",
"columns": [
"githubAvatarUrl"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
13 changes: 13 additions & 0 deletions playgrounds/app/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "6",
"when": 1729551859421,
"tag": "0000_last_patch",
"breakpoints": true
}
]
}
18 changes: 16 additions & 2 deletions playgrounds/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
"scripts": {
"dev": "vinxi dev",
"build": "vinxi build",
"start": "vinxi start"
"start": "vinxi start",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:studio": "drizzle-kit studio"
},
"dependencies": {
"@corvu/resizable": "^0.2.3",
"@fontsource/bungee-inline": "^5.1.0",
"@fontsource/roboto": "^5.1.0",
"@kobalte/core": "^0.13.7",
"@libsql/client": "^0.14.0",
"@solid-primitives/storage": "^4.2.1",
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.14.7",
Expand All @@ -20,7 +24,11 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"diff-match-patch-es": "^0.1.0",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.35.3",
"jsonwebtoken": "^9.0.2",
"modern-gif": "^2.0.3",
"nanoid": "^5.0.7",
"ohash": "^1.1.4",
"postcss": "^8.4.38",
"remotion": "^4.0.221",
Expand All @@ -32,9 +40,15 @@
"tailwind-merge": "^2.5.3",
"tailwindcss": "^3.4.3",
"tailwindcss-animate": "^1.0.7",
"vinxi": "^0.4.3"
"vinxi": "^0.4.3",
"zod": "^3.23.8"
},
"engines": {
"node": ">=18"
},
"devDependencies": {
"@types/jsonwebtoken": "^9.0.7",
"drizzle-kit": "^0.26.2",
"tsx": "^4.19.1"
}
}
52 changes: 49 additions & 3 deletions playgrounds/app/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { A, useLocation, useMatch } from '@solidjs/router'
import { A } from '@solidjs/router'
import { Button } from './ui/button'
import { OcMarkgithub2 } from 'solid-icons/oc'
import { FaSolidSun, FaSolidMoon } from 'solid-icons/fa'
import { createThemeSwitcher } from '~/components/theme-switcher'
import { linkStyles } from '~/lib/styles'
import { authToken } from '~/lib/store'
import { Show } from 'solid-js'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '~/components/ui/dropdown-menu'
import { user } from '~/lib/store'
import { TbCode, TbDoorExit } from 'solid-icons/tb'

export default function Nav() {
const [isDarkMode, toggleDarkMode] = createThemeSwitcher()
Expand All @@ -27,7 +36,44 @@ export default function Nav() {
<FaSolidSun class="w-4 h-4 text-neutral-500" />
)}
</button>
{/* <Button>Login/Signup</Button> */}
<Show when={!authToken()}>
<Button
as="a"
href={`https://github.com/login/oauth/authorize?client_id=${
import.meta.env.VITE_GITHUB_CLIENT_ID
}&redirect_uri=${window.location.origin}/oauth`}
>
<OcMarkgithub2 size={24} class="mr-4" />
Login/Signup
</Button>
</Show>
<Show when={Boolean(authToken())}>
<DropdownMenu>
<DropdownMenuTrigger>
<Button class="flex flex-row items-center gap-2">
<img
src={user()?.githubAvatarUrl}
alt={user()?.githubUsername}
class="w-6 h-6 rounded-full"
/>
{user()?.githubUsername}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<A href="/snippets" class="flex flex-row items-center gap-2">
<TbCode /> Snippets
</A>
</DropdownMenuItem>
<DropdownMenuItem>
<A href="/logged-out" class="flex flex-row items-center gap-2">
<TbDoorExit />
Log out
</A>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</Show>
</div>
</nav>
<div class="flex flex-col items-center justify-center p-4">
Expand Down
11 changes: 11 additions & 0 deletions playgrounds/app/src/db/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'dotenv/config'
import { drizzle } from 'drizzle-orm/libsql'
import { schema } from './schema'

export const db = drizzle({
schema: schema,
connection: {
url: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN,
},
})
28 changes: 28 additions & 0 deletions playgrounds/app/src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'

export const usersTable = sqliteTable('users_table', {
id: text().primaryKey(),
email: text().notNull().unique(),
githubId: text().notNull().unique(),
githubUsername: text().notNull().unique(),
githubAvatarUrl: text().notNull().unique(),
createdAt: int().notNull().default(0),
updatedAt: int().notNull().default(0),
})

export const snippetsTable = sqliteTable('snippets_table', {
id: text().primaryKey(),
userId: text()
.notNull()
.references(() => usersTable.id),
title: text().notNull(),
codeLeft: text().notNull(),
codeRight: text().notNull(),
createdAt: int().notNull().default(0),
updatedAt: int().notNull().default(0),
})

export const schema = {
users: usersTable,
snippets: snippetsTable,
}
Loading

0 comments on commit a61d912

Please sign in to comment.