mirror of https://github.com/MaxLeiter/Drift
colocate components
parent
96c4023c14
commit
96da95818f
@ -1,4 +1,4 @@
|
||||
import PageSeo from "@components/page-seo"
|
||||
import PageSeo from "app/components/page-seo"
|
||||
|
||||
export default function AuthHead() {
|
||||
return <PageSeo title="Sign In" />
|
||||
@ -0,0 +1,5 @@
|
||||
import PageSeo from "app/components/page-seo"
|
||||
|
||||
export default function AuthHead() {
|
||||
return <PageSeo title="Sign Up" />
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
import ShiftBy from "@components/shift-by"
|
||||
import ShiftBy from "app/components/shift-by"
|
||||
import { Button, Popover } from "@geist-ui/core/dist"
|
||||
import ChevronDown from "@geist-ui/icons/chevronDown"
|
||||
import CodeIcon from "@geist-ui/icons/fileFunction"
|
||||
@ -1,5 +1,5 @@
|
||||
import type { Document } from "@lib/types"
|
||||
import DocumentComponent from "@components/edit-document"
|
||||
import DocumentComponent from "./edit-document"
|
||||
import { ChangeEvent, memo, useCallback } from "react"
|
||||
|
||||
const DocumentList = ({
|
||||
@ -1,7 +1,7 @@
|
||||
import { ChangeEvent, memo, useEffect, useState } from "react"
|
||||
import { Text } from "@geist-ui/core/dist"
|
||||
|
||||
import ShiftBy from "@components/shift-by"
|
||||
import ShiftBy from "app/components/shift-by"
|
||||
import styles from "../post.module.css"
|
||||
import { Input } from "@geist-ui/core/dist"
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Fieldset, useToasts } from "@geist-ui/core/dist"
|
||||
import { User } from "@lib/types"
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
import { adminFetcher } from "."
|
||||
import { adminFetcher } from "./admin"
|
||||
import Table from "rc-table"
|
||||
import SettingsGroup from "@components/settings-group"
|
||||
import ActionDropdown from "./action-dropdown"
|
||||
@ -1,5 +1,5 @@
|
||||
"use client"
|
||||
import ShiftBy from "@components/shift-by"
|
||||
import ShiftBy from "app/components/shift-by"
|
||||
import { Spacer, Tabs, Card, Textarea, Text } from "@geist-ui/core/dist"
|
||||
import Image from "next/image"
|
||||
import styles from "./home.module.css"
|
||||
@ -1,4 +1,4 @@
|
||||
import PageSeo from "@components/page-seo"
|
||||
import PageSeo from "app/components/page-seo"
|
||||
|
||||
export default function Head() {
|
||||
return <PageSeo title="Drift - Your profile" isPrivate />
|
||||
@ -1,8 +1,8 @@
|
||||
import { redirect } from "next/navigation"
|
||||
import { getPostsByUser } from "@lib/server/prisma"
|
||||
import PostList from "@components/post-list"
|
||||
import PostList from "app/components/post-list"
|
||||
import { getCurrentUser } from "@lib/server/session"
|
||||
import Header from "@components/header"
|
||||
import Header from "app/components/header"
|
||||
import { authOptions } from "@lib/server/auth"
|
||||
|
||||
export default async function Mine() {
|
||||
@ -1,4 +1,4 @@
|
||||
import PageSeo from "@components/page-seo"
|
||||
import PageSeo from "app/components/page-seo"
|
||||
|
||||
export default function Head() {
|
||||
return <PageSeo title="Drift - Settings" isPrivate />
|
||||
@ -1,7 +1,7 @@
|
||||
import Header from "@components/header"
|
||||
import SettingsGroup from "@components/settings-group"
|
||||
import Password from "@components/settings/sections/password"
|
||||
import Profile from "@components/settings/sections/profile"
|
||||
import Header from "app/components/header"
|
||||
import SettingsGroup from "./components/settings-group"
|
||||
import Password from "app/settings/components/sections/password"
|
||||
import Profile from "app/settings/components/sections/profile"
|
||||
import { authOptions } from "@lib/server/auth"
|
||||
import { getCurrentUser } from "@lib/server/session"
|
||||
import { redirect } from "next/navigation"
|
||||
@ -1,66 +0,0 @@
|
||||
import Header from "@components/header"
|
||||
import { GeistProvider, CssBaseline, Themes, Page } from "@geist-ui/core/dist"
|
||||
import type { NextComponentType, NextPageContext } from "next"
|
||||
import { SkeletonTheme } from "react-loading-skeleton"
|
||||
|
||||
const App = ({
|
||||
Component,
|
||||
pageProps
|
||||
}: {
|
||||
Component: NextComponentType<NextPageContext, any, any>
|
||||
pageProps: any
|
||||
}) => {
|
||||
const skeletonBaseColor = "var(--light-gray)"
|
||||
const skeletonHighlightColor = "var(--lighter-gray)"
|
||||
|
||||
const customTheme = Themes.createFromLight({
|
||||
type: "custom",
|
||||
palette: {
|
||||
background: "var(--bg)",
|
||||
foreground: "var(--fg)",
|
||||
accents_1: "var(--lightest-gray)",
|
||||
accents_2: "var(--lighter-gray)",
|
||||
accents_3: "var(--light-gray)",
|
||||
accents_4: "var(--gray)",
|
||||
accents_5: "var(--darker-gray)",
|
||||
accents_6: "var(--darker-gray)",
|
||||
accents_7: "var(--darkest-gray)",
|
||||
accents_8: "var(--darkest-gray)",
|
||||
border: "var(--light-gray)",
|
||||
warning: "var(--warning)"
|
||||
},
|
||||
expressiveness: {
|
||||
dropdownBoxShadow: "0 0 0 1px var(--light-gray)",
|
||||
shadowSmall: "0 0 0 1px var(--light-gray)",
|
||||
shadowLarge: "0 0 0 1px var(--light-gray)",
|
||||
shadowMedium: "0 0 0 1px var(--light-gray)"
|
||||
},
|
||||
layout: {
|
||||
gap: "var(--gap)",
|
||||
gapHalf: "var(--gap-half)",
|
||||
gapQuarter: "var(--gap-quarter)",
|
||||
gapNegative: "var(--gap-negative)",
|
||||
gapHalfNegative: "var(--gap-half-negative)",
|
||||
gapQuarterNegative: "var(--gap-quarter-negative)",
|
||||
radius: "var(--radius)"
|
||||
},
|
||||
font: {
|
||||
mono: "var(--font-mono)",
|
||||
sans: "var(--font-sans)"
|
||||
}
|
||||
})
|
||||
return (
|
||||
<GeistProvider themes={[customTheme]} themeType={"custom"}>
|
||||
<SkeletonTheme
|
||||
baseColor={skeletonBaseColor}
|
||||
highlightColor={skeletonHighlightColor}
|
||||
>
|
||||
<CssBaseline />
|
||||
<Header />
|
||||
<Component {...pageProps} />
|
||||
</SkeletonTheme>
|
||||
</GeistProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
@ -1,27 +0,0 @@
|
||||
import config from "@lib/config"
|
||||
import { User } from "@prisma/client"
|
||||
import prisma from "@lib/server/prisma"
|
||||
import { sign } from "jsonwebtoken"
|
||||
|
||||
export async function generateAndExpireAccessToken(userId: User["id"]) {
|
||||
const token = sign({ id: userId }, config.jwt_secret, { expiresIn: "2d" })
|
||||
|
||||
await prisma.authTokens.create({
|
||||
data: {
|
||||
userId: userId,
|
||||
token: token
|
||||
}
|
||||
})
|
||||
|
||||
// TODO: set expiredReason?
|
||||
prisma.authTokens.deleteMany({
|
||||
where: {
|
||||
userId: userId,
|
||||
token: {
|
||||
not: token
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return token
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
import "@styles/globals.css"
|
||||
import type { AppProps as NextAppProps } from "next/app"
|
||||
|
||||
import "react-loading-skeleton/dist/skeleton.css"
|
||||
import Head from "next/head"
|
||||
import { ThemeProvider } from "next-themes"
|
||||
import App from "@components/app"
|
||||
import React from "react"
|
||||
|
||||
type AppProps<P = any> = {
|
||||
pageProps: P
|
||||
} & Omit<NextAppProps<P>, "pageProps">
|
||||
|
||||
function MyApp({ Component, pageProps }: AppProps) {
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<meta charSet="utf-8" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1, shrink-to-fit=no"
|
||||
/>
|
||||
<link
|
||||
rel="apple-touch-icon"
|
||||
sizes="180x180"
|
||||
href="/assets/apple-touch-icon.png"
|
||||
/>
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/png"
|
||||
sizes="32x32"
|
||||
href="/assets/favicon-32x32.png"
|
||||
/>
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/png"
|
||||
sizes="16x16"
|
||||
href="/assets/favicon-16x16.png"
|
||||
/>
|
||||
<link rel="manifest" href="/site.webmanifest" />
|
||||
<link
|
||||
rel="mask-icon"
|
||||
href="/assets/safari-pinned-tab.svg"
|
||||
color="#5bbad5"
|
||||
/>
|
||||
<meta name="apple-mobile-web-app-title" content="Drift" />
|
||||
<meta name="application-name" content="Drift" />
|
||||
<meta name="msapplication-TileColor" content="#da532c" />
|
||||
<meta name="theme-color" content="#ffffff" />
|
||||
<title>Drift</title>
|
||||
</Head>
|
||||
<ThemeProvider defaultTheme="system" disableTransitionOnChange>
|
||||
<App Component={Component} pageProps={pageProps} />
|
||||
</ThemeProvider>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default MyApp
|
||||
@ -1,39 +0,0 @@
|
||||
import { CssBaseline } from "@geist-ui/core/dist"
|
||||
import Document, {
|
||||
Html,
|
||||
Head,
|
||||
Main,
|
||||
NextScript,
|
||||
DocumentContext
|
||||
} from "next/document"
|
||||
|
||||
class MyDocument extends Document {
|
||||
static async getInitialProps(ctx: DocumentContext) {
|
||||
const initialProps = await Document.getInitialProps(ctx)
|
||||
const styles = CssBaseline.flush()
|
||||
|
||||
return {
|
||||
...initialProps,
|
||||
styles: (
|
||||
<>
|
||||
{initialProps.styles}
|
||||
{styles}
|
||||
</> // TODO: Investigate typescript
|
||||
) as any
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Html lang="en">
|
||||
<Head />
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</body>
|
||||
</Html>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default MyDocument
|
||||
@ -1,12 +0,0 @@
|
||||
import ErrorComponent from "@components/error"
|
||||
|
||||
function Error({ statusCode }: { statusCode: number }) {
|
||||
return <ErrorComponent status={statusCode} />
|
||||
}
|
||||
|
||||
Error.getInitialProps = ({ res, err }: { res: any; err: any }) => {
|
||||
const statusCode = res ? res.statusCode : err ? err.statusCode : 404
|
||||
return { statusCode }
|
||||
}
|
||||
|
||||
export default Error
|
||||
@ -1,51 +0,0 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next"
|
||||
import prisma from "@lib/server/prisma"
|
||||
import bcrypt from "bcrypt"
|
||||
import { signin } from "@lib/server/signin"
|
||||
import { setCookie } from "cookies-next"
|
||||
import { TOKEN_COOKIE_NAME, USER_COOKIE_NAME } from "@lib/constants"
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
const { username, password } = req.body
|
||||
if (!username || !password) {
|
||||
return res.status(400).json({ error: "Missing param" })
|
||||
}
|
||||
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
username
|
||||
}
|
||||
})
|
||||
|
||||
if (!user || !user.password) {
|
||||
return res.status(401).json({ error: "Unauthorized" })
|
||||
}
|
||||
|
||||
const isPasswordValid = await bcrypt.compare(password, user.password)
|
||||
if (!isPasswordValid) {
|
||||
return res.status(401).json({ error: "Unauthorized" })
|
||||
}
|
||||
|
||||
const token = await signin(user.id, req, res)
|
||||
setCookie(TOKEN_COOKIE_NAME, token, {
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 24 * 7, // 1 week
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
req,
|
||||
res
|
||||
})
|
||||
setCookie(USER_COOKIE_NAME, user.id, {
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 24 * 7, // 1 week
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
req,
|
||||
res
|
||||
})
|
||||
|
||||
return res.status(201).json({ token: token, userId: user.id })
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next"
|
||||
import { createUser } from "@lib/server/prisma"
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
const { username, password, serverPassword } = req.body
|
||||
const { user, token } = await createUser(username, password, serverPassword)
|
||||
|
||||
return res.status(201).json({ token: token, userId: user.id })
|
||||
}
|
||||
Loading…
Reference in New Issue