Skip to content

Commit

Permalink
Configurações iniciais do NextAuth e realizando a autenticação básica…
Browse files Browse the repository at this point in the history
… com as proprias rotas da api interna
  • Loading branch information
pablogeokar committed Sep 29, 2024
1 parent 9dbfe78 commit 96c07c2
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 112 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Passo a passo para a criação de um porojeto do zero absoluto
# Passo a passo para a criação de um projeto do zero absoluto
Estou utilizando o pnpm como gerenciador de pacotes, utilize o seu gerenciador a sua escolha.

1 - Criar um novo projeto
```bash
Expand All @@ -12,4 +13,14 @@ pnpm add next-auth@beta zod
3 - Inicializando o shadcn para a estilização em conjunto com o tailwind
```bash
pnpm dlx shadcn-ui@latest init
```

4 - exemplo de instalação dos componentes do shadcn de forma individual
```bash
pnpm dlx shadcn@latest add card
```

5 - Iniciando a configuração do Next-Auth
```bash
pnpm dlx auth secret
```
3 changes: 3 additions & 0 deletions app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { handlers } from "@/auth";

export const { GET, POST } = handlers;
Binary file removed app/fonts/GeistMonoVF.woff
Binary file not shown.
Binary file removed app/fonts/GeistVF.woff
Binary file not shown.
19 changes: 3 additions & 16 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import type { Metadata } from "next";
import localFont from "next/font/local";
import { Inter } from "next/font/google";
import "./globals.css";

const geistSans = localFont({
src: "./fonts/GeistVF.woff",
variable: "--font-geist-sans",
weight: "100 900",
});
const geistMono = localFont({
src: "./fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
weight: "100 900",
});
const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Create Next App",
Expand All @@ -25,11 +16,7 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
<body className={`${inter.className} antialiased`}>{children}</body>
</html>
);
}
117 changes: 23 additions & 94 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,101 +1,30 @@
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import Image from "next/image";

export default function Home() {
export default async function Home() {
return (
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
<main className="flex flex-col gap-8 row-start-2 items-center sm:items-start">
<Image
className="dark:invert"
src="https://nextjs.org/icons/next.svg"
alt="Next.js logo"
width={180}
height={38}
priority
/>
<ol className="list-inside list-decimal text-sm text-center sm:text-left font-[family-name:var(--font-geist-mono)]">
<li className="mb-2">
Get started by editing{" "}
<code className="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-semibold">
app/page.tsx
</code>
.
</li>
<li>Save and see your changes instantly.</li>
</ol>

<div className="flex gap-4 items-center flex-col sm:flex-row">
<a
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5"
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
className="dark:invert"
src="https://nextjs.org/icons/vercel.svg"
alt="Vercel logomark"
width={20}
height={20}
/>
Deploy now
</a>
<a
className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44"
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Read our docs
</a>
</div>
</main>
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/file.svg"
alt="File icon"
width={16}
height={16}
/>
Learn
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/window.svg"
alt="Window icon"
width={16}
height={16}
/>
Examples
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<main className="flex min-h-screen flex-col items-center justify-center p-24">
<Card className="max-w-sm">
<CardHeader>
<Image
aria-hidden
src="https://nextjs.org/icons/globe.svg"
alt="Globe icon"
width={16}
height={16}
className="rounded-lg"
src="https://images.pexels.com/photos/1374510/pexels-photo-1374510.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2"
alt="img"
width={500}
height={500}
priority
/>
Go to nextjs.org →
</a>
</footer>
</div>
</CardHeader>
<CardContent>
<CardTitle className="mb-2 text-2xl font-bold">
Welcome, user!
</CardTitle>
<p className="text-muted-foreground">
If you are learning something valuable from this video, please like
and subscribe to my channel.
</p>
</CardContent>
</Card>
</main>
);
}
38 changes: 38 additions & 0 deletions auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import NextAuth from "next-auth";
import Credentials from "next-auth/providers/credentials";
import async from "./app/page";

export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
Credentials({
credentials: {
email: { label: "Email", type: "email", placeholder: "seu@email.com" },
password: {
label: "Password",
type: "password",
placeholder: "sua senha",
},
},
async authorize(credentials) {
let user = null;

// validate credentials

// get user

user = {
id: "1",
name: "Aditya Singh",
email: "jojo@jojo.com",
};

if (!user) {
console.log("Invalid credentials");
return null;
}

return user;
},
}),
],
});
79 changes: 79 additions & 0 deletions components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as React from "react"

import { cn } from "@/lib/utils"

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-lg border bg-card text-card-foreground shadow-sm",
className
)}
{...props}
/>
))
Card.displayName = "Card"

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
))
CardHeader.displayName = "CardHeader"

const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h3
ref={ref}
className={cn(
"text-2xl font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
CardTitle.displayName = "CardTitle"

const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
CardDescription.displayName = "CardDescription"

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
))
CardContent.displayName = "CardContent"

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex items-center p-6 pt-0", className)}
{...props}
/>
))
CardFooter.displayName = "CardFooter"

export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
5 changes: 5 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { auth as middleware } from "@/auth";

export const config = {
matcher: ["/((?!api|_next/static|_next/image|.*\\.png$).*)"],
};
6 changes: 5 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
images: {
remotePatterns: [{ hostname: "images.pexels.com" }],
},
};

export default nextConfig;

0 comments on commit 96c07c2

Please sign in to comment.