-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from SkidGod4444/revert-26-feature/auth
Revert "add auth "
- Loading branch information
Showing
34 changed files
with
205 additions
and
2,975 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 +0,0 @@ | ||
public-hoist-pattern[]=* | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,104 +1,63 @@ | ||
import { prisma } from "@repo/db"; | ||
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", | ||
]; | ||
import { handle } from "hono/vercel"; | ||
|
||
export const runtime = "nodejs"; | ||
|
||
const app = new Hono<{ | ||
Variables: { | ||
user: typeof auth.$Infer.Session.user | null; | ||
session: typeof auth.$Infer.Session.session | null; | ||
}; | ||
}>().basePath("/api"); | ||
|
||
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") ?? ""; | ||
const app = new Hono().basePath("/api"); | ||
|
||
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", | ||
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 new Response("Forbidden", { | ||
status: 403, | ||
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, | ||
}); | ||
}); | ||
}); | ||
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); | ||
export const OPTIONS = handle(app); | ||
|
||
export { GET, PATCH, POST, DELETE }; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.