Skip to content

Commit

Permalink
local login and register
Browse files Browse the repository at this point in the history
  • Loading branch information
monsterooo committed Jan 5, 2024
1 parent ed2bbbd commit 23ca232
Show file tree
Hide file tree
Showing 24 changed files with 639 additions and 318 deletions.
6 changes: 0 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ GITHUB_ACCESS_TOKEN=""

DATABASE_URL="postgresql://postgres:postgres@localhost:54322/postgres?schema=nextjs-starter"

# Email
SMTP_FROM=""
POSTMARK_API_TOKEN=""
POSTMARK_SIGN_IN_TEMPLATE=""
POSTMARK_ACTIVATION_TEMPLATE=""

# Subscriptions (Stripe)
STRIPE_API_KEY=""
STRIPE_WEBHOOK_SECRET=""
Expand Down
20 changes: 10 additions & 10 deletions app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Metadata } from "next"
import Link from "next/link"
import { Metadata } from "next";
import Link from "next/link";

import { cn } from "@/lib/utils"
import { buttonVariants } from "@/components/ui/button"
import { LoginForm } from "@/components/auth/login-form"
import { Icons } from "@/components/icons"
import { UserAuthForm } from "@/components/user-auth-form"
import { cn } from "@/lib/utils";
import { buttonVariants } from "@/components/ui/button";
import { LoginForm } from "@/components/auth/login-form";
import { Icons } from "@/components/icons";
import { UserAuthForm } from "@/components/user-auth-form";

export const metadata: Metadata = {
title: "Login",
description: "Login to your account",
}
};

export default function LoginPage() {
return (
Expand All @@ -37,8 +37,8 @@ export default function LoginPage() {
Enter your email to sign in to your account
</p>
</div>
<UserAuthForm />
<LoginForm />
<UserAuthForm />
<p className="px-8 text-center text-sm text-muted-foreground">
<Link
href="/register"
Expand All @@ -49,5 +49,5 @@ export default function LoginPage() {
</p>
</div>
</div>
)
);
}
18 changes: 9 additions & 9 deletions app/(auth)/register/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Link from "next/link"
import Link from "next/link";

import { cn } from "@/lib/utils"
import { buttonVariants } from "@/components/ui/button"
import { RegisterForm } from "@/components/auth/register-form"
import { Icons } from "@/components/icons"
import { UserAuthForm } from "@/components/user-auth-form"
import { cn } from "@/lib/utils";
import { buttonVariants } from "@/components/ui/button";
import { RegisterForm } from "@/components/auth/register-form";
import { Icons } from "@/components/icons";
import { UserAuthForm } from "@/components/user-auth-form";

export const metadata = {
title: "Create an account",
description: "Create an account to get started.",
}
};

export default async function RegisterPage() {
return (
Expand All @@ -35,8 +35,8 @@ export default async function RegisterPage() {
Enter your email below to create your account
</p>
</div>
<UserAuthForm />
<RegisterForm />
<UserAuthForm />
<p className="px-8 text-center text-sm text-muted-foreground">
By clicking continue, you agree to our{" "}
<Link
Expand All @@ -57,5 +57,5 @@ export default async function RegisterPage() {
</div>
</div>
</div>
)
);
}
39 changes: 19 additions & 20 deletions app/(dashboard)/dashboard/billing/page.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
import { redirect } from "next/navigation"

import { authOptions } from "@/lib/auth"
import { getCurrentUser } from "@/lib/session"
import { stripe } from "@/lib/stripe"
import { getUserSubscriptionPlan } from "@/lib/subscription"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { redirect } from "next/navigation";
import { authOptions } from "@/lib/auth.config";
import { currentUser } from "@/lib/session";
import { stripe } from "@/lib/stripe";
import { getUserSubscriptionPlan } from "@/lib/subscription";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import { BillingForm } from "@/components/billing-form"
import { DashboardHeader } from "@/components/header"
import { Icons } from "@/components/icons"
import { DashboardShell } from "@/components/shell"
} from "@/components/ui/card";
import { BillingForm } from "@/components/billing-form";
import { DashboardHeader } from "@/components/header";
import { Icons } from "@/components/icons";
import { DashboardShell } from "@/components/shell";

export const metadata = {
title: "Billing",
description: "Manage billing and your subscription plan.",
}
};

export default async function BillingPage() {
const user = await getCurrentUser()
const user = await currentUser();

if (!user) {
redirect(authOptions?.pages?.signIn || "/login")
redirect(authOptions?.pages?.signIn || "/login");
}

const subscriptionPlan = await getUserSubscriptionPlan(user.id)
const subscriptionPlan = await getUserSubscriptionPlan(user.id);

// If user has a pro plan, check cancel status on Stripe.
let isCanceled = false
let isCanceled = false;
if (subscriptionPlan.isPro && subscriptionPlan.stripeSubscriptionId) {
const stripePlan = await stripe.subscriptions.retrieve(
subscriptionPlan.stripeSubscriptionId
)
isCanceled = stripePlan.cancel_at_period_end
);
isCanceled = stripePlan.cancel_at_period_end;
}

return (
Expand Down Expand Up @@ -72,5 +71,5 @@ export default async function BillingPage() {
/>
</div>
</DashboardShell>
)
);
}
22 changes: 11 additions & 11 deletions app/(dashboard)/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { notFound } from "next/navigation"
import { notFound } from "next/navigation";

import { dashboardConfig } from "@/config/dashboard"
import { getCurrentUser } from "@/lib/session"
import { MainNav } from "@/components/main-nav"
import { DashboardNav } from "@/components/nav"
import { SiteFooter } from "@/components/site-footer"
import { UserAccountNav } from "@/components/user-account-nav"
import { dashboardConfig } from "@/config/dashboard";
import { currentUser } from "@/lib/session";
import { MainNav } from "@/components/main-nav";
import { DashboardNav } from "@/components/nav";
import { SiteFooter } from "@/components/site-footer";
import { UserAccountNav } from "@/components/user-account-nav";

interface DashboardLayoutProps {
children?: React.ReactNode
children?: React.ReactNode;
}

export default async function DashboardLayout({
children,
}: DashboardLayoutProps) {
const user = await getCurrentUser()
const user = await currentUser();

if (!user) {
return notFound()
return notFound();
}

return (
Expand All @@ -44,5 +44,5 @@ export default async function DashboardLayout({
</div>
<SiteFooter className="border-t" />
</div>
)
);
}
27 changes: 13 additions & 14 deletions app/(dashboard)/dashboard/settings/page.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { redirect } from "next/navigation"

import { authOptions } from "@/lib/auth"
import { getCurrentUser } from "@/lib/session"
import { DashboardHeader } from "@/components/header"
import { DashboardShell } from "@/components/shell"
import { UserNameForm } from "@/components/user-name-form"
import { currentUser } from "@/lib/session";
import { DashboardHeader } from "@/components/header";
import { DashboardShell } from "@/components/shell";
import { UserNameForm } from "@/components/user-name-form";

export const metadata = {
title: "Settings",
description: "Manage account and website settings.",
}
};

export default async function SettingsPage() {
const user = await getCurrentUser()
const user = await currentUser();

console.log("~~settings user ~~", user);

if (!user) {
redirect(authOptions?.pages?.signIn || "/login")
}
// if (!user) {
// redirect(authOptions?.pages?.signIn || "/login")
// }

return (
<DashboardShell>
Expand All @@ -25,8 +24,8 @@ export default async function SettingsPage() {
text="Manage account and website settings."
/>
<div className="grid gap-10">
<UserNameForm user={{ id: user.id, name: user.name || "" }} />
{/* <UserNameForm user={{ id: user.id, name: user.name || "" }} /> */}
</div>
</DashboardShell>
)
);
}
63 changes: 30 additions & 33 deletions app/(marketing)/blog/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
import { notFound } from "next/navigation"
import { allAuthors, allPosts } from "contentlayer/generated"

import { Mdx } from "@/components/mdx-components"

import "@/styles/mdx.css"
import { Metadata } from "next"
import Image from "next/image"
import Link from "next/link"

import { env } from "@/env.mjs"
import { absoluteUrl, cn, formatDate } from "@/lib/utils"
import { buttonVariants } from "@/components/ui/button"
import { Icons } from "@/components/icons"
import { notFound } from "next/navigation";
import { allAuthors, allPosts } from "contentlayer/generated";
import { Mdx } from "@/components/mdx-components";
import "@/styles/mdx.css";
import { Metadata } from "next";
import Image from "next/image";
import Link from "next/link";
import { env } from "@/env.mjs";
import { absoluteUrl, cn, formatDate } from "@/lib/utils";
import { buttonVariants } from "@/components/ui/button";
import { Icons } from "@/components/icons";

interface PostPageProps {
params: {
slug: string[]
}
slug: string[];
};
}

async function getPostFromParams(params) {
const slug = params?.slug?.join("/")
const post = allPosts.find((post) => post.slugAsParams === slug)
const slug = params?.slug?.join("/");
const post = allPosts.find((post) => post.slugAsParams === slug);

if (!post) {
null
null;
}

return post
return post;
}

export async function generateMetadata({
params,
}: PostPageProps): Promise<Metadata> {
const post = await getPostFromParams(params)
const post = await getPostFromParams(params);

if (!post) {
return {}
return {};
}

const url = env.NEXT_PUBLIC_APP_URL
const url = env.NEXT_PUBLIC_APP_URL;

const ogUrl = new URL(`${url}/api/og`)
ogUrl.searchParams.set("heading", post.title)
ogUrl.searchParams.set("type", "Blog Post")
ogUrl.searchParams.set("mode", "dark")
const ogUrl = new URL(`${url}/api/og`);
ogUrl.searchParams.set("heading", post.title);
ogUrl.searchParams.set("type", "Blog Post");
ogUrl.searchParams.set("mode", "dark");

return {
title: post.title,
Expand Down Expand Up @@ -72,27 +69,27 @@ export async function generateMetadata({
description: post.description,
images: [ogUrl.toString()],
},
}
};
}

export async function generateStaticParams(): Promise<
PostPageProps["params"][]
> {
return allPosts.map((post) => ({
slug: post.slugAsParams.split("/"),
}))
}));
}

export default async function PostPage({ params }: PostPageProps) {
const post = await getPostFromParams(params)
const post = await getPostFromParams(params);

if (!post) {
notFound()
notFound();
}

const authors = post.authors.map((author) =>
allAuthors.find(({ slug }) => slug === `/authors/${author}`)
)
);

return (
<article className="container relative max-w-3xl py-6 lg:py-10">
Expand Down Expand Up @@ -165,5 +162,5 @@ export default async function PostPage({ params }: PostPageProps) {
</Link>
</div>
</article>
)
);
}

0 comments on commit 23ca232

Please sign in to comment.