-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b49b450
commit e775aeb
Showing
34 changed files
with
2,944 additions
and
163 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Hono } from "hono"; | ||
const app = new Hono(); | ||
import { prisma } from "@repo/db"; | ||
app | ||
.get("/", async (c) => { | ||
const user = await prisma.user.findMany(); | ||
return c.json({ | ||
user, | ||
}); | ||
}) | ||
.patch(async (c) => { | ||
const name = await c.req.json(); | ||
const test = await prisma.user.update({ | ||
where: { | ||
id: "123", | ||
}, | ||
data: { | ||
name: name.name, | ||
}, | ||
}); | ||
return c.json({ | ||
test, | ||
}); | ||
}) | ||
.delete(async (c) => { | ||
const test = await prisma.user.delete({ | ||
where: { | ||
id: "2", | ||
}, | ||
}); | ||
return c.json({ | ||
test, | ||
}); | ||
}) | ||
.post(async (c) => { | ||
const body = await c.req.json(); | ||
console.log(body); | ||
const test = await prisma.user.create({ | ||
data: body, | ||
}); | ||
return c.json({ | ||
test, | ||
}); | ||
}); | ||
|
||
export default app; |
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,62 @@ | ||
import { Hono } from "hono"; | ||
import { sendBatchEmail, sendEmail } from "@repo/mail"; | ||
import { mailBatchSchema, mailSchema } from "@repo/types"; | ||
import { zValidator } from "@hono/zod-validator"; | ||
|
||
const app = new Hono(); | ||
|
||
app | ||
.post("/send", zValidator("json", mailSchema), async (c) => { | ||
const { email, subject } = c.req.valid("json"); | ||
const { data, error } = await sendEmail(email, subject); | ||
if (error) { | ||
return c.json( | ||
{ | ||
message: "Email sent failed", | ||
}, | ||
400, | ||
); | ||
} | ||
return c.json( | ||
{ | ||
message: "Email sent successfully", | ||
data, | ||
}, | ||
200, | ||
); | ||
}) | ||
.get((c) => { | ||
return c.json({ | ||
message: "mail api is alive", | ||
status: 200, | ||
}); | ||
}); | ||
|
||
app | ||
.post("/send-batch", zValidator("json", mailBatchSchema), async (c) => { | ||
const { emails, subject } = c.req.valid("json"); | ||
const { data, error } = await sendBatchEmail(emails, subject); | ||
if (error) { | ||
return c.json( | ||
{ | ||
message: "Email sent failed", | ||
}, | ||
400, | ||
); | ||
} | ||
return c.json( | ||
{ | ||
message: "All Emails sent successfully", | ||
data, | ||
}, | ||
200, | ||
); | ||
}) | ||
.get((c) => { | ||
return c.json({ | ||
message: "all mail api is alive", | ||
status: 200, | ||
}); | ||
}); | ||
|
||
export default app; |
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,63 +1,103 @@ | ||
import { prisma } from "@repo/db"; | ||
import { Hono } from "hono"; | ||
import { handle } from "hono/vercel"; | ||
import { Hono } from "hono"; | ||
import { auth } from "@repo/auth"; | ||
import { cors } from "hono/cors"; | ||
import mail from "./mail"; | ||
import hello from "./hello"; | ||
|
||
const allowedOrigins = [ | ||
"http://localhost:3003", | ||
"https://www.plura.pro", | ||
"http://app.plura.pro", | ||
]; | ||
|
||
export const runtime = "nodejs"; | ||
|
||
const app = new Hono().basePath("/api"); | ||
const app = new Hono<{ | ||
Variables: { | ||
user: typeof auth.$Infer.Session.user | null; | ||
session: typeof auth.$Infer.Session.session | null; | ||
}; | ||
}>().basePath("/api"); | ||
|
||
app | ||
.get("/hello", async (c) => { | ||
const test = await prisma.user.findMany(); | ||
return c.json({ | ||
test, | ||
}); | ||
}) | ||
.patch(async (c) => { | ||
const name = await c.req.json(); | ||
const test = await prisma.user.update({ | ||
where: { | ||
id: "123", | ||
}, | ||
data: { | ||
name: name.name, | ||
}, | ||
}); | ||
return c.json({ | ||
test, | ||
}); | ||
}) | ||
.delete(async (c) => { | ||
const test = await prisma.user.delete({ | ||
where: { | ||
id: "2", | ||
app.use( | ||
"/auth/**", | ||
cors({ | ||
origin: allowedOrigins, | ||
allowHeaders: ["Content-Type", "Authorization"], | ||
allowMethods: ["POST", "GET", "OPTIONS"], | ||
exposeHeaders: ["Content-Length"], | ||
maxAge: 600, | ||
credentials: true, | ||
}), | ||
); | ||
app.options("/auth/**", (c) => { | ||
const origin = c.req.raw.headers.get("origin") ?? ""; | ||
|
||
if (allowedOrigins.includes(origin)) { | ||
return new Response(null, { | ||
status: 204, | ||
headers: { | ||
"Access-Control-Allow-Origin": origin, | ||
"Access-Control-Allow-Methods": "GET, POST, OPTIONS", | ||
"Access-Control-Allow-Headers": "Content-Type, Authorization", | ||
"Access-Control-Allow-Credentials": "true", | ||
"Access-Control-Max-Age": "600", | ||
}, | ||
}); | ||
return c.json({ | ||
test, | ||
}); | ||
}) | ||
.post(async (c) => { | ||
const body = await c.req.json(); | ||
console.log(body); | ||
const test = await prisma.user.create({ | ||
data: body, | ||
}); | ||
return c.json({ | ||
test, | ||
}); | ||
} | ||
|
||
return new Response("Forbidden", { | ||
status: 403, | ||
}); | ||
}); | ||
app.use("*", async (c, next) => { | ||
const session = await auth.api.getSession({ headers: c.req.raw.headers }); | ||
|
||
if (!session) { | ||
c.set("user", null); | ||
c.set("session", null); | ||
return next(); | ||
} | ||
|
||
c.set("user", session.user); | ||
c.set("session", session.session); | ||
return next(); | ||
}); | ||
|
||
app.get("/health", async (c) => { | ||
return c.json({ | ||
message: "i am alive", | ||
status: 200, | ||
}); | ||
}); | ||
app.get("/session", async (c) => { | ||
const session = c.get("session"); | ||
const user = c.get("user"); | ||
|
||
if (!user) return c.body(null, 401); | ||
|
||
return c.json({ | ||
session, | ||
user, | ||
}); | ||
}); | ||
app.route("/hello", hello); | ||
app.route("/mail", mail); | ||
|
||
app.on(["POST", "GET"], "/auth/**", (c) => { | ||
return auth.handler(c.req.raw); | ||
}); | ||
app.get("/multi-sessions", async (c) => { | ||
const res = await auth.api.listDeviceSessions({ | ||
headers: c.req.raw.headers, | ||
}); | ||
return c.json(res); | ||
}); | ||
const GET = handle(app); | ||
const POST = handle(app); | ||
const PATCH = handle(app); | ||
const DELETE = handle(app); | ||
const OPTIONS = handle(app); | ||
|
||
export { GET, PATCH, POST, DELETE }; | ||
export { GET, PATCH, POST, DELETE, OPTIONS }; |
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
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,14 @@ | ||
import AccountSwitcher from "@/components/custom/account-switcher"; | ||
import { getMultipleSessions, getSession } from "@/lib/server"; | ||
|
||
export default async function page() { | ||
const session = await getSession(); | ||
const multipleSessions = await getMultipleSessions(); | ||
return ( | ||
<div> | ||
<AccountSwitcher session={multipleSessions} activeSession={session} /> | ||
<pre className="font-sm">{JSON.stringify(session, null, 1)}</pre> | ||
<pre>{JSON.stringify(multipleSessions,null,2)}</pre> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import SignInComponent from "@/components/custom/signInComponent"; | ||
|
||
export default function page() { | ||
return ( | ||
<div className="w-full h-screen flex items-center justify-center"> | ||
<SignInComponent /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import SignUpComponent from "@/components/custom/signUpComponent"; | ||
|
||
export default function page() { | ||
return ( | ||
<div className="w-full h-screen flex items-center justify-center"> | ||
<SignUpComponent /> | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.