Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rec #603

Merged
merged 34 commits into from
Feb 23, 2024
Merged

Rec #603

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d839f94
fix(deps): update dependency lucide-react to ^0.334.0
renovate[bot] Feb 19, 2024
98ec618
chore(deps): update typescript-eslint monorepo to v7.0.2
renovate[bot] Feb 19, 2024
c246ece
chore(deps): update dependency @types/react to v18.2.57
renovate[bot] Feb 19, 2024
8b19548
fix(deps): update dependency inquirer to v9.2.15
renovate[bot] Feb 20, 2024
87ac2a1
fix(deps): update dependency dotenv to v16.4.5
renovate[bot] Feb 20, 2024
8ca185a
chore(deps): update dependency vitest to v1.3.1
renovate[bot] Feb 20, 2024
0dbaed5
fix(deps): update dependency lucide-react to ^0.335.0
renovate[bot] Feb 20, 2024
314d680
fix(deps): update prisma monorepo to v5.10.1
renovate[bot] Feb 20, 2024
9d2f213
fix(deps): update dependency eslint-plugin-tailwindcss to v3.14.3
renovate[bot] Feb 21, 2024
8a92fe0
fix(deps): update prisma monorepo to v5.10.2
renovate[bot] Feb 21, 2024
82c5b6c
fix(deps): update dependency lucide-react to ^0.336.0
renovate[bot] Feb 22, 2024
95f492a
fix(deps): update dependency nodemailer to v6.9.10
renovate[bot] Feb 22, 2024
18f3b76
chore(deps): update dependency @types/node to v20.11.20
renovate[bot] Feb 22, 2024
fc9507c
fix(deps): update dependency nodemon to v3.1.0
renovate[bot] Feb 22, 2024
7b93f9a
refactor: env
rharkor Feb 23, 2024
b183d28
refactor: create caller
rharkor Feb 23, 2024
ad8d065
refactor: muted colors
rharkor Feb 23, 2024
dd2b1a0
refactor: sign-in
rharkor Feb 23, 2024
317f94e
refactor: auth middleware
rharkor Feb 23, 2024
62699ef
refactor: remove server only
rharkor Feb 23, 2024
4a9ed33
refactor: active session
rharkor Feb 23, 2024
9a4de17
refactor: w,h to size
rharkor Feb 23, 2024
ac8e4b0
refactor: contant location
rharkor Feb 23, 2024
5e30dec
refactor: schemas location
rharkor Feb 23, 2024
07b50ec
fix: t3 env
rharkor Feb 23, 2024
e3df5b2
fix: logger
rharkor Feb 23, 2024
aea3f19
refactor: redis
rharkor Feb 23, 2024
18635cc
refactor: lang
rharkor Feb 23, 2024
4de0b7c
refactor: remove json api
rharkor Feb 23, 2024
95a9977
refactor: remove unused link
rharkor Feb 23, 2024
3096086
Merge pull request #601 from rharkor/dev
rharkor Feb 23, 2024
464d8ac
chore(release): 3.6.0-rec.2 [skip ci]
semantic-release-bot Feb 23, 2024
c971846
Merge branch 'main' into rec
rharkor Feb 23, 2024
3e0a1cc
chore(release): 3.6.1-rec.1 [skip ci]
semantic-release-bot Feb 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 133 additions & 139 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
"only-allow-many": "^1.2.2",
"semantic-release": "^23.0.0"
},
"version": "3.6.0"
"version": "3.6.1-rec.1"
}
4 changes: 2 additions & 2 deletions packages/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ ENV=development
NEXT_PUBLIC_BASE_URL=http://localhost:3000
DATABASE_PRISMA_URL="postgresql://postgres:postgres@localhost:5432/postgres?schema=public"
DATABASE_URL_NON_POOLING="postgresql://postgres:postgres@localhost:5432/postgres?schema=public"
PASSWORD_HASHER_SECRET=QltDSmVBMDhHKENWcjFgN3J1Vmw=
PASSWORD_HASHER_SECRET=secret
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=PGJwbCE+WiJILGZ+K1ZqU24mIX5tVH0=
NEXTAUTH_SECRET=secret
GITHUB_CLIENT_ID=secret
GITHUB_CLIENT_SECRET=secret
[email protected]
Expand Down
4 changes: 2 additions & 2 deletions packages/app/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export const env = createEnv({
.enum(["true", "false"])
.optional()
.transform((value) => value === "true"),
PASSWORD_HASHER_SECRET: z.string().min(16),
PASSWORD_HASHER_SECRET: z.string(),
DATABASE_PRISMA_URL: z.string().min(1),
DATABASE_URL_NON_POOLING: z.string().optional(),
NEXTAUTH_SECRET: z.string().min(16),
NEXTAUTH_SECRET: z.string(),
NEXTAUTH_URL: z.string().optional(),
GITHUB_CLIENT_ID: z.string().min(1),
GITHUB_CLIENT_SECRET: z.string().min(1),
Expand Down
5 changes: 2 additions & 3 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@next-auth/prisma-adapter": "^1.0.7",
"@nextui-org/react": "^2.2.9",
"@prisma/client": "^5.6.0",
"@t3-oss/env-nextjs": "^0.9.0",
"@t3-oss/env-nextjs": "^0.9.2",
"@tanstack/react-query": "^4.36.1",
"@total-typescript/ts-reset": "^0.5.0",
"@trpc/client": "^10.43.0",
Expand Down Expand Up @@ -56,7 +56,7 @@
"eslint-plugin-unused-imports": "^3.0.0",
"framer-motion": "^11.0.0",
"ioredis": "^5.3.2",
"lucide-react": "^0.331.0",
"lucide-react": "^0.336.0",
"negotiator": "^0.6.3",
"next": "^14.0.0",
"next-auth": "^4.24.5",
Expand All @@ -72,7 +72,6 @@
"react-hook-form": "^7.45.4",
"react-toastify": "^10.0.0",
"request-ip": "^3.3.0",
"server-only": "^0.0.1",
"sharp": "^0.33.0",
"superjson": "^2.0.0",
"tailwind-merge": "^2.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/app/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ config()
import chalk from "chalk"
import { Spinner } from "cli-spinner"

import { rolesAsObject } from "@/constants"
import { hash } from "@/lib/bcrypt"
import { logger } from "@lib/logger"
import { PrismaClient } from "@prisma/client"

import { rolesAsObject } from "../src/types/constants"

const env = {
AUTH_ADMIN_EMAIL: process.env.AUTH_ADMIN_EMAIL,
AUTH_ADMIN_PASSWORD: process.env.AUTH_ADMIN_PASSWORD,
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/auth/_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
signUpSchema,
verifyTotpResponseSchema,
verifyTotpSchema,
} from "@/lib/schemas/auth"
} from "@/api/auth/schemas"
import { authenticatedProcedure, publicProcedure, router } from "@/lib/server/trpc"

import { desactivateTotp, generateTotpSecret, recover2FA, register, verifyTotp } from "./mutations"
Expand Down
12 changes: 6 additions & 6 deletions packages/app/src/api/auth/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { env } from "env.mjs"
import { authenticator } from "otplib"
import { z } from "zod"

import { hash } from "@/lib/bcrypt"
import { sendMail } from "@/lib/mailer"
import { prisma } from "@/lib/prisma"
import { redis } from "@/lib/redis"
import {
desactivateTotpSchema,
generateTotpSecretResponseSchema,
recover2FASchema,
signUpSchema,
verifyTotpSchema,
} from "@/lib/schemas/auth"
} from "@/api/auth/schemas"
import { emailVerificationExpiration, rolesAsObject } from "@/constants"
import { hash } from "@/lib/bcrypt"
import { sendMail } from "@/lib/mailer"
import { prisma } from "@/lib/prisma"
import { redis } from "@/lib/redis"
import { html, plainText, subject } from "@/lib/templates/mail/verify-email"
import { ApiError, ensureLoggedIn, generateRandomSecret, handleApiError } from "@/lib/utils/server-utils"
import { apiInputFromSchema } from "@/types"
import { emailVerificationExpiration, rolesAsObject } from "@/types/constants"
import { logger } from "@lib/logger"
import { Prisma } from "@prisma/client"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as z from "zod"

import { maxPasswordLength, minPasswordLength } from "@/lib/auth/constants"
import { TDictionary } from "@/lib/langs"

import { maxPasswordLength, minPasswordLength } from "../auth/constants"

import { userSchema } from "./user"
import { userSchema } from "../me/schemas"

export const passwordSchema = (dictionary?: TDictionary) =>
z
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/me/_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
updateUserSchema,
verifyEmailResponseSchema,
verifyEmailSchema,
} from "@/lib/schemas/user"
} from "@/api/me/schemas"
import {
authenticatedNoEmailVerificationProcedure,
authenticatedProcedure,
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/api/me/email/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { randomUUID } from "crypto"
import { env } from "env.mjs"
import { i18n } from "i18n-config"

import { sendVerificationEmailSchema, verifyEmailSchema } from "@/api/me/schemas"
import { emailVerificationExpiration, resendEmailVerificationExpiration } from "@/constants"
import { sendMail } from "@/lib/mailer"
import { prisma } from "@/lib/prisma"
import { sendVerificationEmailSchema, verifyEmailSchema } from "@/lib/schemas/user"
import { html, plainText, subject } from "@/lib/templates/mail/verify-email"
import { ApiError, handleApiError } from "@/lib/utils/server-utils"
import { apiInputFromSchema } from "@/types"
import { emailVerificationExpiration, resendEmailVerificationExpiration } from "@/types/constants"
import { logger } from "@lib/logger"

export const sendVerificationEmail = async ({ input }: apiInputFromSchema<typeof sendVerificationEmailSchema>) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/api/me/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { env } from "env.mjs"

import { updateUserSchema } from "@/api/me/schemas"
import { rolesAsObject } from "@/constants"
import { prisma } from "@/lib/prisma"
import { s3Client } from "@/lib/s3"
import { updateUserSchema } from "@/lib/schemas/user"
import { ApiError } from "@/lib/utils/server-utils"
import { ensureLoggedIn, handleApiError } from "@/lib/utils/server-utils"
import { apiInputFromSchema } from "@/types"
import { rolesAsObject } from "@/types/constants"
import { DeleteObjectCommand } from "@aws-sdk/client-s3"
import { logger } from "@lib/logger"
import { Prisma } from "@prisma/client"
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/api/me/password/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { randomUUID } from "crypto"
import { env } from "env.mjs"
import { i18n } from "i18n-config"

import { forgotPasswordSchema, resetPasswordSchema } from "@/api/me/schemas"
import { resendResetPasswordExpiration, resetPasswordExpiration, rolesAsObject } from "@/constants"
import { hash } from "@/lib/bcrypt"
import { sendMail } from "@/lib/mailer"
import { prisma } from "@/lib/prisma"
import { forgotPasswordSchema, resetPasswordSchema } from "@/lib/schemas/user"
import { html, plainText, subject } from "@/lib/templates/mail/reset-password"
import { ApiError, handleApiError } from "@/lib/utils/server-utils"
import { apiInputFromSchema } from "@/types"
import { resendResetPasswordExpiration, resetPasswordExpiration, rolesAsObject } from "@/types/constants"
import { logger } from "@lib/logger"

export const forgotPassword = async ({ input }: apiInputFromSchema<typeof forgotPasswordSchema>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { z } from "zod"

import { jsonApiQuerySchema, jsonApiResponseSchema } from "../json-api"
import { TDictionary } from "../langs"
import { queriesOptionPage, queriesOptionPerPage } from "@/lib/queries-options"

import { emailSchema, passwordSchemaWithRegex, usernameSchema } from "./auth"
import { TDictionary } from "../../lib/langs"
import { emailSchema, passwordSchemaWithRegex, usernameSchema } from "../auth/schemas"

export const userSchema = (dictionary?: TDictionary) =>
z.object({
Expand Down Expand Up @@ -43,17 +43,20 @@ export const sessionsSchema = () =>
})

export const getActiveSessionsSchema = (dictionary?: TDictionary) =>
jsonApiQuerySchema(dictionary)
.pick({
page: true,
perPage: true,
sort: true,
})
.optional()
z.object({
page: queriesOptionPage(dictionary),
perPage: queriesOptionPerPage(dictionary),
})

export const getActiveSessionsResponseSchema = () =>
jsonApiResponseSchema().extend({
z.object({
data: z.array(sessionsSchema()).optional(),
meta: z.object({
total: z.number(),
page: z.number(),
perPage: z.number(),
totalPages: z.number(),
}),
})

export const deleteSessionSchema = () =>
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/me/sessions/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { deleteSessionSchema } from "@/api/me/schemas"
import { redis } from "@/lib/redis"
import { deleteSessionSchema } from "@/lib/schemas/user"
import { ensureLoggedIn, handleApiError } from "@/lib/utils/server-utils"
import { apiInputFromSchema } from "@/types"

Expand Down
9 changes: 5 additions & 4 deletions packages/app/src/api/me/sessions/queries.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { z } from "zod"

import { getJsonApiSkip, getJsonApiTake } from "@/lib/json-api"
import { getActiveSessionsResponseSchema, getActiveSessionsSchema, sessionsSchema } from "@/api/me/schemas"
import { redis } from "@/lib/redis"
import { getActiveSessionsResponseSchema, getActiveSessionsSchema, sessionsSchema } from "@/lib/schemas/user"
import { ensureLoggedIn, handleApiError } from "@/lib/utils/server-utils"
import { apiInputFromSchema } from "@/types"

Expand All @@ -13,8 +12,10 @@ export const getActiveSessions = async ({
try {
ensureLoggedIn(session)

const skip = getJsonApiSkip(input)
const take = getJsonApiTake(input)
const { page, perPage } = input

const skip = (page - 1) * perPage
const take = perPage
const allSessionsKeys = await redis.keys(`session:${session.user.id}:*`)
const allSessions = await redis.mget(allSessionsKeys)
const activeSessions = allSessions
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/upload/_router.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { presignedUrlResponseSchema, presignedUrlSchema } from "@/lib/schemas/upload"
import { authenticatedProcedure, router } from "@/lib/server/trpc"

import { presignedUrl } from "./mutations"
import { presignedUrlResponseSchema, presignedUrlSchema } from "./schemas"

export const uploadRouter = router({
presignedUrl: authenticatedProcedure
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/api/upload/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { randomUUID } from "crypto"
import { env } from "env.mjs"
import { z } from "zod"

import { maxUploadSize } from "@/constants"
import { prisma } from "@/lib/prisma"
import { s3Client } from "@/lib/s3"
import { presignedUrlResponseSchema, presignedUrlSchema } from "@/lib/schemas/upload"
import { stringToSlug } from "@/lib/utils"
import { ApiError, ensureLoggedIn, handleApiError } from "@/lib/utils/server-utils"
import { apiInputFromSchema } from "@/types"
import { maxUploadSize } from "@/types/constants"
import { DeleteObjectCommand } from "@aws-sdk/client-s3"
import { createPresignedPost } from "@aws-sdk/s3-presigned-post"
import { logger } from "@lib/logger"

import { presignedUrlResponseSchema, presignedUrlSchema } from "./schemas"

export const presignedUrl = async ({ input, ctx: { session } }: apiInputFromSchema<typeof presignedUrlSchema>) => {
ensureLoggedIn(session)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async function Profile({
<SignoutButton>{dictionary.signOut}</SignoutButton>
</div>
<ProfileDetails dictionary={dictionary} hasVerifiedEmail={hasVerifiedEmail} />
<UserActiveSessions dictionary={dictionary} session={session} />
<UserActiveSessions dictionary={dictionary} />
</CardBody>
</Card>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { useForm } from "react-hook-form"
import { toast } from "react-toastify"
import { z } from "zod"

import { forgotPasswordSchema } from "@/api/me/schemas"
import AutoRefresh from "@/components/auto-refresh"
import FormField from "@/components/ui/form"
import { resendResetPasswordExpiration } from "@/constants"
import { useDictionary } from "@/contexts/dictionary/utils"
import { forgotPasswordSchema } from "@/lib/schemas/user"
import { trpc } from "@/lib/trpc/client"
import { resendResetPasswordExpiration } from "@/types/constants"
import { zodResolver } from "@hookform/resolvers/zod"
import { Button, Tooltip } from "@nextui-org/react"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { useForm } from "react-hook-form"
import { toast } from "react-toastify"
import { z } from "zod"

import { recover2FASchema } from "@/api/auth/schemas"
import FormField from "@/components/ui/form"
import { useDictionary } from "@/contexts/dictionary/utils"
import { authRoutes } from "@/lib/auth/constants"
import { recover2FASchema } from "@/lib/schemas/auth"
import { trpc } from "@/lib/trpc/client"
import { cn } from "@/lib/utils"
import { zodResolver } from "@hookform/resolvers/zod"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { useForm } from "react-hook-form"
import { toast } from "react-toastify"
import { z } from "zod"

import { resetPasswordSchema } from "@/api/me/schemas"
import FormField from "@/components/ui/form"
import { useDictionary } from "@/contexts/dictionary/utils"
import { authRoutes } from "@/lib/auth/constants"
import { resetPasswordSchema } from "@/lib/schemas/user"
import { trpc } from "@/lib/trpc/client"
import { zodResolver } from "@hookform/resolvers/zod"
import { Button } from "@nextui-org/react"
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/auth/github-sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function GithubSignIn({
isDisabled={isLoading}
>
{isLoading ? (
<Spinner classNames={{ base: "mr-2", wrapper: "h-4 w-4" }} color="current" size="sm" />
<Spinner classNames={{ base: "mr-2", wrapper: "size-4" }} color="current" size="sm" />
) : (
<Icons.gitHub className="mr-2 size-4" />
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/auth/login-user-auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { ArrowBigDown, BadgeInfo } from "lucide-react"
import { useForm } from "react-hook-form"
import * as z from "zod"

import { signInSchema } from "@/api/auth/schemas"
import { useDictionary } from "@/contexts/dictionary/utils"
import { authRoutes } from "@/lib/auth/constants"
import { handleSignError, handleSignIn } from "@/lib/auth/handle-sign"
import { signInSchema } from "@/lib/schemas/auth"
import { cn, ensureRelativeUrl } from "@/lib/utils"
import { zodResolver } from "@hookform/resolvers/zod"
import { Button, Card, CardBody, Link } from "@nextui-org/react"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { useRouter } from "next/navigation"
import { useForm } from "react-hook-form"
import * as z from "zod"

import { signUpSchema } from "@/api/auth/schemas"
import { useDictionary } from "@/contexts/dictionary/utils"
import { authRoutes } from "@/lib/auth/constants"
import { handleSignError, handleSignIn } from "@/lib/auth/handle-sign"
import { TDictionary } from "@/lib/langs"
import { signUpSchema } from "@/lib/schemas/auth"
import { trpc } from "@/lib/trpc/client"
import { cn } from "@/lib/utils"
import { handleMutationError } from "@/lib/utils/client-utils"
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/components/profile/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { useState } from "react"
import { Camera } from "lucide-react"
import { toast } from "react-toastify"

import { maxUploadSize } from "@/constants"
import { useAccount } from "@/contexts/account"
import { useDictionary } from "@/contexts/dictionary/utils"
import { trpc } from "@/lib/trpc/client"
import { cn } from "@/lib/utils"
import { getImageUrl } from "@/lib/utils/client-utils"
import { maxUploadSize } from "@/types/constants"
import { logger } from "@lib/logger"
import { Avatar, Button, Modal, ModalBody, ModalContent, Skeleton, Spinner } from "@nextui-org/react"

Expand Down Expand Up @@ -141,7 +141,7 @@ export default function UpdateAvatar({ account }: { account: ReturnType<typeof u
{updateUserMutation.isLoading ? (
<Spinner
classNames={{
wrapper: "h-4 w-4",
wrapper: "size-4",
}}
color="current"
size="sm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Dispatch, SetStateAction } from "react"
import { UAParser } from "ua-parser-js"
import { z } from "zod"

import { sessionsSchema } from "@/api/me/schemas"
import { Icons } from "@/components/icons"
import { TDictionary } from "@/lib/langs"
import { sessionsSchema } from "@/lib/schemas/user"
import { cn, getTimeBetween } from "@/lib/utils"
import { Button, Skeleton as NSkeleton } from "@nextui-org/react"

Expand Down
Loading