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

Revert "add auth " #28

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading