Skip to content

Commit

Permalink
chore: remove prisma, litefs, and auth code
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitdalal committed Apr 18, 2024
1 parent f964cbf commit 829014d
Show file tree
Hide file tree
Showing 87 changed files with 68 additions and 9,706 deletions.
4 changes: 0 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
LITEFS_DIR="/litefs/data"
DATABASE_PATH="./prisma/data.db"
DATABASE_URL="file:./data.db?connection_limit=1"
CACHE_DATABASE_PATH="./other/cache.db"
SESSION_SECRET="super-duper-s3cret"
HONEYPOT_SECRET="super-duper-s3cret"
INTERNAL_COMMAND_TOKEN="some-made-up-token"
Expand Down
63 changes: 0 additions & 63 deletions app/components/search-bar.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as Sentry from '@sentry/remix'
import { isbot } from 'isbot'
import { renderToPipeableStream } from 'react-dom/server'
import { getEnv, init } from './utils/env.server.ts'
import { getInstanceInfo } from './utils/litefs.server.ts'
import { NonceProvider } from './utils/nonce-provider.ts'
import { makeTimings } from './utils/timing.server.ts'

Expand All @@ -33,11 +32,8 @@ export default async function handleRequest(...args: DocRequestArgs) {
remixContext,
loadContext,
] = args
const { currentInstance, primaryInstance } = await getInstanceInfo()
responseHeaders.set('fly-region', process.env.FLY_REGION ?? 'unknown')
responseHeaders.set('fly-app', process.env.FLY_APP_NAME ?? 'unknown')
responseHeaders.set('fly-primary-instance', primaryInstance)
responseHeaders.set('fly-instance', currentInstance)

const callbackName = isbot(request.headers.get('user-agent'))
? 'onAllReady'
Expand Down Expand Up @@ -84,11 +80,8 @@ export default async function handleRequest(...args: DocRequestArgs) {
}

export async function handleDataRequest(response: Response) {
const { currentInstance, primaryInstance } = await getInstanceInfo()
response.headers.set('fly-region', process.env.FLY_REGION ?? 'unknown')
response.headers.set('fly-app', process.env.FLY_APP_NAME ?? 'unknown')
response.headers.set('fly-primary-instance', primaryInstance)
response.headers.set('fly-instance', currentInstance)

return response
}
Expand Down
141 changes: 3 additions & 138 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
type MetaFunction,
} from '@remix-run/node'
import {
Form,
Link,
Links,
Meta,
Expand All @@ -20,40 +19,24 @@ import {
useFetcher,
useFetchers,
useLoaderData,
useMatches,
useSubmit,
} from '@remix-run/react'
import { withSentry } from '@sentry/remix'
import { useRef } from 'react'
import { HoneypotProvider } from 'remix-utils/honeypot/react'
import { z } from 'zod'
import { GeneralErrorBoundary } from './components/error-boundary.tsx'
import { EpicProgress } from './components/progress-bar.tsx'
import { SearchBar } from './components/search-bar.tsx'
import { useToast } from './components/toaster.tsx'
import { Button } from './components/ui/button.tsx'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuPortal,
DropdownMenuTrigger,
} from './components/ui/dropdown-menu.tsx'
import { Icon, href as iconsHref } from './components/ui/icon.tsx'
import { EpicToaster } from './components/ui/sonner.tsx'
import tailwindStyleSheetUrl from './styles/tailwind.css?url'
import { getUserId, logout } from './utils/auth.server.ts'
import { ClientHintCheck, getHints, useHints } from './utils/client-hints.tsx'
import { prisma } from './utils/db.server.ts'
import { getEnv } from './utils/env.server.ts'
import { honeypot } from './utils/honeypot.server.ts'
import { combineHeaders, getDomainUrl, getUserImgSrc } from './utils/misc.tsx'
import { getDomainUrl } from './utils/misc.tsx'
import { useNonce } from './utils/nonce-provider.ts'
import { useRequestInfo } from './utils/request-info.ts'
import { type Theme, setTheme, getTheme } from './utils/theme.server.ts'
import { makeTimings, time } from './utils/timing.server.ts'
import { getToast } from './utils/toast.server.ts'
import { useOptionalUser, useUser } from './utils/user.ts'

export const links: LinksFunction = () => {
return [
Expand Down Expand Up @@ -86,48 +69,11 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
}

export async function loader({ request }: LoaderFunctionArgs) {
const timings = makeTimings('root loader')
const userId = await time(() => getUserId(request), {
timings,
type: 'getUserId',
desc: 'getUserId in root',
})

const user = userId
? await time(
() =>
prisma.user.findUniqueOrThrow({
select: {
id: true,
name: true,
username: true,
image: { select: { id: true } },
roles: {
select: {
name: true,
permissions: {
select: { entity: true, action: true, access: true },
},
},
},
},
where: { id: userId },
}),
{ timings, type: 'find user', desc: 'find user in root' },
)
: null
if (userId && !user) {
console.info('something weird happened')
// something weird happened... The user is authenticated but we can't find
// them in the database. Maybe they were deleted? Let's log them out.
await logout({ request, redirectTo: '/' })
}
const { toast, headers: toastHeaders } = await getToast(request)
const honeyProps = honeypot.getInputProps()

return json(
{
user,
requestInfo: {
hints: getHints(request),
origin: getDomainUrl(request),
Expand All @@ -141,10 +87,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
honeyProps,
},
{
headers: combineHeaders(
{ 'Server-Timing': timings.toString() },
toastHeaders,
),
headers: toastHeaders ?? {},
},
)
}
Expand Down Expand Up @@ -219,11 +162,7 @@ function Document({
function App() {
const data = useLoaderData<typeof loader>()
const nonce = useNonce()
const user = useOptionalUser()
const theme = useTheme()
const matches = useMatches()
const isOnSearchPage = matches.find(m => m.id === 'routes/users+/index')
const searchBar = isOnSearchPage ? null : <SearchBar status="idle" />
const allowIndexing = data.ENV.ALLOW_INDEXING !== 'false'
useToast(data.toast)

Expand All @@ -236,21 +175,8 @@ function App() {
>
<div className="flex h-screen flex-col justify-between">
<header className="container py-6">
<nav className="flex flex-wrap items-center justify-between gap-4 sm:flex-nowrap md:gap-8">
<nav>
<Logo />
<div className="ml-auto hidden max-w-sm flex-1 sm:block">
{searchBar}
</div>
<div className="flex items-center gap-10">
{user ? (
<UserDropdown />
) : (
<Button asChild variant="default" size="lg">
<Link to="/login">Log In</Link>
</Button>
)}
</div>
<div className="block w-full sm:hidden">{searchBar}</div>
</nav>
</header>

Expand Down Expand Up @@ -293,67 +219,6 @@ function AppWithProviders() {

export default withSentry(AppWithProviders)

function UserDropdown() {
const user = useUser()
const submit = useSubmit()
const formRef = useRef<HTMLFormElement>(null)
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button asChild variant="secondary">
<Link
to={`/users/${user.username}`}
// this is for progressive enhancement
onClick={e => e.preventDefault()}
className="flex items-center gap-2"
>
<img
className="h-8 w-8 rounded-full object-cover"
alt={user.name ?? user.username}
src={getUserImgSrc(user.image?.id)}
/>
<span className="text-body-sm font-bold">
{user.name ?? user.username}
</span>
</Link>
</Button>
</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent sideOffset={8} align="start">
<DropdownMenuItem asChild>
<Link prefetch="intent" to={`/users/${user.username}`}>
<Icon className="text-body-md" name="avatar">
Profile
</Icon>
</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link prefetch="intent" to={`/users/${user.username}/notes`}>
<Icon className="text-body-md" name="pencil-2">
Notes
</Icon>
</Link>
</DropdownMenuItem>
<DropdownMenuItem
asChild
// this prevents the menu from closing before the form submission is completed
onSelect={event => {
event.preventDefault()
submit(formRef.current)
}}
>
<Form action="/logout" method="POST" ref={formRef}>
<Icon className="text-body-md" name="exit">
<button type="submit">Logout</button>
</Icon>
</Form>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenu>
)
}

/**
* @returns the user's theme preference, or the client hint theme if the user
* has not set a preference.
Expand Down
Loading

0 comments on commit 829014d

Please sign in to comment.