Skip to content

Commit

Permalink
Merge pull request #28 from SkidGod4444/revert-26-feature/auth
Browse files Browse the repository at this point in the history
Revert "add auth "
  • Loading branch information
SkidGod4444 authored Nov 10, 2024
2 parents 24af3a1 + 3cd7b93 commit b5a8441
Show file tree
Hide file tree
Showing 34 changed files with 205 additions and 2,975 deletions.
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
public-hoist-pattern[]=*
46 changes: 0 additions & 46 deletions apps/api/app/api/[[...route]]/hello.ts

This file was deleted.

62 changes: 0 additions & 62 deletions apps/api/app/api/[[...route]]/mail.ts

This file was deleted.

121 changes: 40 additions & 81 deletions apps/api/app/api/[[...route]]/route.ts
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 };
8 changes: 2 additions & 6 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@
"format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache"
},
"dependencies": {
"@hono/node-server": "^1.13.5",
"@hono/zod-validator": "^0.4.1",
"@repo/auth": "workspace:*",
"@repo/db": "workspace:*",
"contentlayer2": "^0.5.3",
"hono": "^4.6.9",
"next": "15.0.2",
"react": "19.0.0-rc-02c0e824-20241028",
"react-dom": "19.0.0-rc-02c0e824-20241028",
"zod": "^3.23.8"
"react-dom": "19.0.0-rc-02c0e824-20241028"
},
"devDependencies": {
"@types/node": "18.11.18",
"@types/react": "18.0.26",
"@types/react-dom": "18.0.10",
"dotenv": "^16.4.5",
"typescript": "^5"
}
}
10 changes: 4 additions & 6 deletions apps/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
Expand All @@ -34,10 +34,8 @@
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"src/**/*.ts",
"src/**/*.d.ts"
, "../../packages/types/auth.ts" ],
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
Expand Down
1 change: 1 addition & 0 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"next": "15.0.2",
"next-themes": "^0.4.3",
"react": "19.0.0-rc-02c0e824-20241028",
"react-beautiful-dnd": "^13.1.1",
"react-dom": "19.0.0-rc-02c0e824-20241028",
"react-hook-form": "^7.53.1",
"recharts": "^2.13.3",
Expand Down
14 changes: 0 additions & 14 deletions apps/www/app/(auth)/dashboard/page.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions apps/www/app/(auth)/sign-in/page.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions apps/www/app/(auth)/sign-up/page.tsx

This file was deleted.

Loading

0 comments on commit b5a8441

Please sign in to comment.