-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update dependencies * wip * wip * wip * wip * wip * wip
- Loading branch information
Showing
86 changed files
with
622 additions
and
4,131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
name: 📦 Release Packages | ||
# name: 📦 Release Packages | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- 'apps/**' | ||
# on: | ||
# push: | ||
# branches: | ||
# - main | ||
# paths-ignore: | ||
# - 'apps/**' | ||
|
||
jobs: | ||
test: | ||
name: 🧪 Run tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: latest | ||
- name: 📦 Install dependencies | ||
run: bun install | ||
- name: 🔍 Run type checking | ||
run: bun run typecheck | ||
- name: 🔬 Run linting | ||
run: bun run lint | ||
- name: 🧪 Run unit tests | ||
run: bun run test | ||
# jobs: | ||
# test: | ||
# name: 🧪 Run tests | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - uses: actions/checkout@v4 | ||
# - uses: oven-sh/setup-bun@v1 | ||
# with: | ||
# bun-version: latest | ||
# - name: 📦 Install dependencies | ||
# run: bun install | ||
# - name: 🔍 Run type checking | ||
# run: bun run typecheck | ||
# - name: 🔬 Run linting | ||
# run: bun run lint | ||
# - name: 🧪 Run unit tests | ||
# run: bun run test | ||
|
||
create-release: | ||
name: 📦 Create Release | ||
needs: [test] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: latest | ||
- name: 📦 Install dependencies | ||
run: bun install | ||
- name: 🏗️ Build packages | ||
run: bun turbo build --filter=languine --filter=@languine/react-email | ||
- name: 🔖 Create and publish versions | ||
uses: changesets/action@master | ||
with: | ||
version: bun run changeset version | ||
commit: "chore: update versions" | ||
title: "chore: update versions" | ||
publish: bun run changeset publish | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
# create-release: | ||
# name: 📦 Create Release | ||
# needs: [test] | ||
# runs-on: ubuntu-latest | ||
# permissions: | ||
# contents: write | ||
# pull-requests: write | ||
# steps: | ||
# - uses: actions/checkout@v4 | ||
# with: | ||
# fetch-depth: 0 | ||
# - uses: oven-sh/setup-bun@v1 | ||
# with: | ||
# bun-version: latest | ||
# - name: 📦 Install dependencies | ||
# run: bun install | ||
# - name: 🏗️ Build packages | ||
# run: bun turbo build --filter=languine --filter=@languine/react-email | ||
# - name: 🔖 Create and publish versions | ||
# uses: changesets/action@master | ||
# with: | ||
# version: bun run changeset version | ||
# commit: "chore: update versions" | ||
# title: "chore: update versions" | ||
# publish: bun run changeset publish | ||
# env: | ||
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
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 |
---|---|---|
|
@@ -60,7 +60,6 @@ dist/ | |
|
||
# deps | ||
node_modules/ | ||
.wrangler | ||
|
||
# env | ||
.env | ||
|
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
22 changes: 22 additions & 0 deletions
22
apps/web/src/app/[locale]/(dashboard)/cli/success/page.tsx
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,22 @@ | ||
import { getSession } from "@/lib/session"; | ||
import { getI18n } from "@/locales/server"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export default async function Page() { | ||
const t = await getI18n(); | ||
const session = await getSession(); | ||
|
||
if (!session.data) { | ||
redirect("/login"); | ||
} | ||
|
||
return ( | ||
<div className="w-full h-screen flex flex-col items-center justify-center"> | ||
<h1 className="text-xl font-medium mb-4">{t("cli.success.title")}</h1> | ||
<p className="text-center mb-2 text-sm text-secondary"> | ||
{t("cli.success.description")} <span>{session.data.user.email}</span> | ||
</p> | ||
<p className="text-sm text-secondary">{t("cli.success.description_2")}</p> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { CLI_TOKEN_NAME, saveCLISession } from "@/lib/auth/cli"; | ||
import { getSession } from "@/lib/session"; | ||
import { Ratelimit } from "@upstash/ratelimit"; | ||
import { Redis } from "@upstash/redis"; | ||
import { NextResponse } from "next/server"; | ||
|
||
const ratelimit = new Ratelimit({ | ||
redis: Redis.fromEnv(), | ||
limiter: Ratelimit.slidingWindow(5, "60s"), | ||
}); | ||
|
||
export async function GET( | ||
request: Request, | ||
{ params }: { params: Promise<{ token: string }> }, | ||
) { | ||
const ip = request.headers.get("x-forwarded-for") ?? "127.0.0.1"; | ||
const { success } = await ratelimit.limit(ip); | ||
|
||
if (!success) { | ||
return NextResponse.json({ error: "Too many requests" }, { status: 429 }); | ||
} | ||
|
||
const { token } = await params; | ||
|
||
const session = await getSession(); | ||
|
||
if (!session?.data) { | ||
const response = NextResponse.redirect(new URL("/login", request.url), { | ||
status: 302, | ||
}); | ||
|
||
if (token) { | ||
response.cookies.set(CLI_TOKEN_NAME, token, { | ||
maxAge: 5 * 60, | ||
}); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
if (session?.data?.session) { | ||
await saveCLISession(session.data.session, token); | ||
} | ||
|
||
const response = NextResponse.redirect(new URL("/cli/success", request.url), { | ||
status: 302, | ||
}); | ||
|
||
response.cookies.delete(CLI_TOKEN_NAME); | ||
|
||
return response; | ||
} |
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,39 @@ | ||
import { db } from "@/db"; | ||
import { users } from "@/db/schema"; | ||
import { getCLISession } from "@/lib/auth/cli"; | ||
import { eq } from "drizzle-orm"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function GET( | ||
request: Request, | ||
{ params }: { params: Promise<{ token: string }> }, | ||
) { | ||
const { token } = await params; | ||
|
||
const cliSession = await getCLISession(token); | ||
|
||
if (!cliSession) { | ||
return NextResponse.json( | ||
{ | ||
success: false, | ||
}, | ||
{ status: 404 }, | ||
); | ||
} | ||
|
||
const user = await db | ||
.select({ | ||
id: users.id, | ||
name: users.name, | ||
email: users.email, | ||
apiKey: users.apiKey, | ||
}) | ||
.from(users) | ||
.where(eq(users.id, cliSession.userId)) | ||
.get(); | ||
|
||
return NextResponse.json({ | ||
success: true, | ||
user, | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { kv } from "@/lib/kv"; | ||
import type { Session } from "better-auth"; | ||
import { cookies } from "next/headers"; | ||
|
||
export const CLI_TOKEN_NAME = "cli-token"; | ||
|
||
export async function saveCLISession(session: Session, token: string) { | ||
await kv.set(`${CLI_TOKEN_NAME}:${token}`, session, { | ||
ex: 5 * 60, | ||
}); | ||
} | ||
|
||
export async function getCLISession(token: string) { | ||
const data = await kv.get<Session>(`${CLI_TOKEN_NAME}:${token}`); | ||
|
||
return data; | ||
} |
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 @@ | ||
import { | ||
createDefaultOrganization, | ||
getDefaultOrganization, | ||
} from "@/db/queries/organization"; | ||
import WelcomeEmail from "@/emails/templates/welcome"; | ||
import { resend } from "@/lib/resend"; | ||
import { waitUntil } from "@vercel/functions"; | ||
import type { Session, User } from "better-auth"; | ||
import { cookies } from "next/headers"; | ||
import { CLI_TOKEN_NAME, saveCLISession } from "./cli"; | ||
|
||
export const databaseHooks = { | ||
user: { | ||
create: { | ||
after: async (user: User) => { | ||
await createDefaultOrganization(user); | ||
|
||
// Send welcome email to new user | ||
try { | ||
waitUntil( | ||
resend.emails.send({ | ||
from: "Languine <[email protected]>", | ||
to: user.email, | ||
subject: "Welcome to Languine", | ||
react: WelcomeEmail({ name: user.name }), | ||
}), | ||
); | ||
} catch (error) { | ||
console.error("Error sending welcome email", error); | ||
} | ||
}, | ||
}, | ||
}, | ||
session: { | ||
create: { | ||
before: async (session: Session) => { | ||
const org = await getDefaultOrganization(session.userId); | ||
|
||
const cookieStore = await cookies(); | ||
const token = cookieStore.get(CLI_TOKEN_NAME); | ||
|
||
if (token?.value) { | ||
await saveCLISession(session, token.value); | ||
|
||
cookieStore.delete(CLI_TOKEN_NAME); | ||
} | ||
|
||
return { | ||
data: { | ||
...session, | ||
activeOrganizationId: org?.organizations?.id, | ||
}, | ||
}; | ||
}, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.