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 "auth" #35

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
124 changes: 42 additions & 82 deletions apps/api/app/api/[[...route]]/route.ts
Original file line number Diff line number Diff line change
@@ -1,103 +1,63 @@
import { handle } from "hono/vercel";
import { prisma } from "@repo/db";
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);
const OPTIONS = handle(app);

export { GET, PATCH, POST, DELETE, OPTIONS };
export { GET, PATCH, POST, DELETE };
9 changes: 0 additions & 9 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.

16 changes: 16 additions & 0 deletions apps/www/app/sign-in/[[...sign-in]]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SiteFooter } from "@/components/custom/site/footer";
import { SiteHeader } from "@/components/custom/site/header";

interface AppLayoutProps {
children: React.ReactNode;
}

export default function AppLayout({ children }: AppLayoutProps) {
return (
<div className="mx-auto w-full border-border/40 dark:border-border min-[1800px]:max-w-[1536px] min-[1800px]:border-x">
<SiteHeader />
<main className="flex-1 px-3">{children}</main>
<SiteFooter />
</div>
);
}
63 changes: 63 additions & 0 deletions apps/www/app/sign-in/[[...sign-in]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Button } from "@/components/ui/button";
import { PiGithubLogoBold } from "react-icons/pi";
import { SiDiscord } from "react-icons/si";
import { FcGoogle } from "react-icons/fc";
import { Input } from "@/components/ui/input";
import Link from "next/link";
export default function SignInPage() {
return (
<div className="container relative">
<div className="absolute bottom-0 left-[-20%] right-0 top-[-10%] h-[500px] w-[500px] rounded-full bg-[radial-gradient(circle_farthest-side,rgba(211,211,211,0.15),rgba(255,255,255,0))]" />
<div className="h-screen w-full flex flex-col items-center justify-center ">
<div className="flex-col w-[26rem] items-center justify-center font-bold bg-clip-text text-transparent bg-gradient-to-b from-neutral-800 to-neutral-700 dark:from-neutal-900 to:neutral-700 drop-shadow-sm dark:to-white relative lg:text-4xl pb-10 z-20 font-sans mx-auto flex gap-4 py-12 md:py-16 lg:py-12 text-center ">
<h1 className=" w-full text-3xl md:text-5xl lg:text-3xl ">
Transform how you work.
</h1>
<article className=" w-full text-3xl md:text-5xl lg:text-3xl">
Log In Your Plura Account
</article>
</div>
<div className="w-[26rem] h-[500px] flex flex-col justify-start items-center ">
<div className="w-full space-y-4 top-0 pt-14 ">
<Button className="w-full border border-border text-xl rounded-lg h-10 bg-transparent text-white hover:bg-neutral-900/90 font-thin ">
<FcGoogle size={30} />
<span>Continue with Google</span>
</Button>
<Button className="w-full border border-border text-xl rounded-lg h-10 bg-transparent text-white hover:bg-neutral-900/90 font-thin flex items-center justify-center ">
<PiGithubLogoBold size={24} />
<span>Continue with Github</span>
</Button>
<Button className="w-full border border-border text-xl rounded-lg h-10 bg-transparent text-white hover:bg-neutral-900/90 font-thin flex items-center justify-center space-x-1">
<SiDiscord />
<span>Continue with Discord</span>
</Button>
</div>
<div className="w-full h-10"></div>
<div className="w-full h-10"></div>
<div className="flex w-full flex-col space-y-2">
<span className=" ml-2 text-muted-foreground text-sm font-normal flex flex-row items-center justify-start">
Email
</span>
<Input
className="h-12 "
placeholder="type your email here"
type="email"
name="email"
/>
<Button
className="bg-neutral-900 text-white border border-border hover:bg-neutral-800"
type="submit"
>
Continue
</Button>
<span className="text-muted-foreground text-sm flex flex-row items-center justify-center hover:underline ">
<Link href={"/sign-up"}>already a member</Link>
</span>
</div>
</div>
{/* experiment here*/}
<div className=""></div>
</div>
</div>
);
}
82 changes: 0 additions & 82 deletions apps/www/components/custom/signinComponent.tsx

This file was deleted.

Loading
Loading