Skip to content

Commit

Permalink
Merge pull request #42 from shreyas0924/signin
Browse files Browse the repository at this point in the history
fix: Fixes #22 and #27 by adding custom signin page and show password with shadcn
  • Loading branch information
hkirat committed Feb 2, 2024
2 parents e12d2fc + 9e57b15 commit 116bd23
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 10,361 deletions.
10,273 changes: 0 additions & 10,273 deletions package-lock.json

This file was deleted.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-slot": "^1.0.2",
"@types/jsonwebtoken": "^9.0.5",
Expand All @@ -41,6 +42,7 @@
"react-notion-x": "^6.16.0",
"react-resizable-panels": "^1.0.7",
"recoil": "^0.7.7",
"sonner": "^1.4.0",
"tailwind-merge": "^2.2.1",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.8.9",
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Providers } from './providers';
import { GoogleAnalytics } from '@/components/analytics/GoogleAnalytics';
import { siteConfig } from '@/config/site-config';
import Footer from '@/components/landing/footer/footer';
import { Toaster } from '@/components/ui/sonner';

const fontSans = FontSans({
subsets: ['latin'],
Expand Down Expand Up @@ -43,6 +44,7 @@ export default function RootLayout({
<Appbar />
<div className="min-h-screen">{children}</div>
<Footer />
<Toaster />
</Providers>
</body>
</html>
Expand Down
122 changes: 122 additions & 0 deletions src/app/signin/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
'use client';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Toaster } from '@/components/ui/sonner';
import { signIn } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import React, { useRef, useState } from 'react';

import { toast } from 'sonner';
const Signin = () => {
const [isPasswordVisible, setIsPasswordVisible] = useState(false);

function togglePasswordVisibility() {
setIsPasswordVisible((prevState: any) => !prevState);
}
const router = useRouter();
const email = useRef('');
const password = useRef('');
const handleSubmit = async (e: React.FormEvent<HTMLButtonElement>) => {
e.preventDefault();
const res = await signIn('credentials', {
email: email.current,
password: password.current,
redirect: false,
});

if (!res?.error) {
router.push('/');
} else {
toast('Error Signing in', {
action: {
label: 'Close',
onClick: () => console.log('Closed Toast'),
},
});
}
};
return (
<section className="flex items-center justify-center h-screen">
<Card className="w-[30%] mx-auto">
<CardHeader>
<CardTitle>Signin to your Account</CardTitle>
</CardHeader>
<CardContent>
<div className="grid w-full items-center gap-4">
<div className="flex flex-col gap-4">
<Label htmlFor="email">Email</Label>
<Input
name="email"
id="email"
placeholder="name@email.com"
onChange={(e) => (email.current = e.target.value)}
/>
</div>
<div className="flex flex-col gap-4">
<Label>Password</Label>
<div className="flex border rounded-lg">
<Input
className="border-0"
name="password"
type={isPasswordVisible ? 'text' : 'password'}
id="password"
placeholder="••••••••"
onChange={(e) => (password.current = e.target.value)}
/>
<button
className="inset-y-0 right-0 flex items-center px-4 text-gray-600"
onClick={togglePasswordVisibility}
>
{isPasswordVisible ? (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className="w-5 h-5"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3.98 8.223A10.477 10.477 0 001.934 12C3.226 16.338 7.244 19.5 12 19.5c.993 0 1.953-.138 2.863-.395M6.228 6.228A10.45 10.45 0 0112 4.5c4.756 0 8.773 3.162 10.065 7.498a10.523 10.523 0 01-4.293 5.774M6.228 6.228L3 3m3.228 3.228l3.65 3.65m7.894 7.894L21 21m-3.228-3.228l-3.65-3.65m0 0a3 3 0 10-4.243-4.243m4.242 4.242L9.88 9.88"
/>
</svg>
) : (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className="w-5 h-5"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M2.036 12.322a1.012 1.012 0 010-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178z"
/>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
/>
</svg>
)}
</button>
</div>
</div>
</div>
<Button className="my-3 w-full" onClick={handleSubmit}>
Login
</Button>
</CardContent>
</Card>
<Toaster />
</section>
);
};

export default Signin;
8 changes: 4 additions & 4 deletions src/components/AppbarAuth.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use client';

import { signOut } from 'next-auth/react';
import { signIn, signOut } from 'next-auth/react';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
//import { useRouter } from 'next/navigation';
import { Button } from './ui/button';

export const AppbarAuth = ({ isInMenu = false }: { isInMenu?: boolean }) => {
const session = useSession();
const router = useRouter();
//const router = useRouter();

return (
<Button
Expand All @@ -18,7 +18,7 @@ export const AppbarAuth = ({ isInMenu = false }: { isInMenu?: boolean }) => {
if (session.data?.user) {
signOut();
} else {
router.push('/api/auth/signin');
signIn();
}
}}
>
Expand Down
6 changes: 5 additions & 1 deletion src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export function Sidebar({
if (content.children && content.children.length > 0) {
// This is a folder with children
return (
<AccordionItem key={content.id} value={`item-${content.id}`} className='text-gray-900 dark:text-white'>
<AccordionItem
key={content.id}
value={`item-${content.id}`}
className="text-gray-900 dark:text-white"
>
<AccordionTrigger>{content.title}</AccordionTrigger>
<AccordionContent>
{/* Render the children of this folder */}
Expand Down
79 changes: 79 additions & 0 deletions src/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 };
25 changes: 25 additions & 0 deletions src/components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from 'react';

import { cn } from '@/lib/utils';

export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
ref={ref}
{...props}
/>
);
},
);
Input.displayName = 'Input';

export { Input };
26 changes: 26 additions & 0 deletions src/components/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';

import * as React from 'react';
import * as LabelPrimitive from '@radix-ui/react-label';
import { cva, type VariantProps } from 'class-variance-authority';

import { cn } from '@/lib/utils';

const labelVariants = cva(
'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
);

const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
));
Label.displayName = LabelPrimitive.Root.displayName;

export { Label };
32 changes: 32 additions & 0 deletions src/components/ui/sonner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use client';

import { useTheme } from 'next-themes';
import React from 'react';
import { Toaster as Sonner } from 'sonner';

type ToasterProps = React.ComponentProps<typeof Sonner>

const Toaster = ({ ...props }: ToasterProps) => {
const { theme = 'system' } = useTheme();

return (
<Sonner
theme={theme as ToasterProps['theme']}
className="toaster group"
toastOptions={{
classNames: {
toast:
'group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg',
description: 'group-[.toast]:text-muted-foreground',
actionButton:
'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground',
cancelButton:
'group-[.toast]:bg-muted group-[.toast]:text-muted-foreground',
},
}}
{...props}
/>
);
};

export { Toaster };
3 changes: 3 additions & 0 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,7 @@ export const authOptions = {
return token;
},
},
pages: {
signIn: '/signin',
},
};
Loading

0 comments on commit 116bd23

Please sign in to comment.