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

auth0 signup method #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
458 changes: 458 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
"lint": "next lint"
},
"dependencies": {
"@auth0/nextjs-auth0": "^3.1.0",
"@types/node": "20.6.3",
"@types/react": "18.2.22",
"@types/react-dom": "18.2.7",
"auth0": "^4.0.1",
"auth0-js": "^9.22.1",
"autoprefixer": "10.4.16",
"dotenv": "^16.3.1",
"eslint": "8.50.0",
"eslint-config-next": "13.5.2",
"next": "13.5.2",
Expand All @@ -21,5 +25,8 @@
"react-dom": "18.2.0",
"tailwindcss": "3.3.3",
"typescript": "5.2.2"
},
"devDependencies": {
"@types/auth0-js": "^9.21.1"
}
}
3 changes: 3 additions & 0 deletions src/app/api/auth/[auth0]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { handleAuth } from '@auth0/nextjs-auth0'

export const GET = handleAuth();
26 changes: 3 additions & 23 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}
html, body {
overflow-y: hidden;
}
6 changes: 5 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import './globals.css'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import { UserProvider } from '@auth0/nextjs-auth0/client'
import 'dotenv/config'

const inter = Inter({ subsets: ['latin'] })

Expand All @@ -16,7 +18,9 @@ export default function RootLayout({
}) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<UserProvider loginUrl='/api/auth/login' profileUrl='/api/auth/me'>
<body className={inter.className}>{children}</body>
</UserProvider>
</html>
)
}
111 changes: 4 additions & 107 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,113 +1,10 @@
import Image from 'next/image'
import Login from '../components/login/Login'
import SignUp from '../components/signup/SignUp'

export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by editing&nbsp;
<code className="font-mono font-bold">src/app/page.tsx</code>
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{' '}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className="dark:invert"
width={100}
height={24}
priority
/>
</a>
</div>
</div>

<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40 before:lg:h-[360px] z-[-1]">
<Image
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>

<div className="mb-32 grid text-center lg:max-w-5xl lg:w-full lg:mb-0 lg:grid-cols-4 lg:text-left">
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Docs{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Find in-depth information about Next.js features and API.
</p>
</a>

<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Learn{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Learn about Next.js in an interactive course with&nbsp;quizzes!
</p>
</a>

<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Templates{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Explore the Next.js 13 playground.
</p>
</a>

<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Deploy{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>
<main>
<SignUp></SignUp>
</main>
)
}
23 changes: 23 additions & 0 deletions src/components/login/Login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use client"
import React from 'react'
import { useUser } from '@auth0/nextjs-auth0/client'
import Link from 'next/link'

type Props = {}

export default function Login({}: Props) {
const { user, error, isLoading } = useUser();

return (
<div className='flex flex-col w-screen h-screen items-center mt-48'>
<div className='text-5xl font-bold'>Login</div>
<div className='w-2/3 border-4 rounded-xl border-black h-12 mt-12 flex items-center'>
<input type='email' name='email' placeholder='Email' className='text-md flex-1 outline-none pl-4' />
</div>
<div className='w-2/3 border-4 rounded-xl border-black h-12 mt-8 flex items-center'>
<input type='password' name='password' placeholder='Password' className='text-md flex-1 outline-none pl-4' />
</div>
</div>
)

}
70 changes: 70 additions & 0 deletions src/components/signup/SignUp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"use client"
import React from 'react'
import { useRef } from 'react'
import config from 'dotenv/config'
import auth0 from 'auth0-js'

type Props = {}

export default function SignUp({}: Props) {
const webAuth = new auth0.WebAuth({
domain: 'dev-36076d8bkapyh3sk.us.auth0.com',
clientID: 'Ksg7UPOnjQyK4l5LBcXUqPROP0KhFwPt'
})

const emailRef = useRef<HTMLInputElement | null>(null);
const passwordRef = useRef<HTMLInputElement | null>(null);

const handleSubmit = (e : any) => {
e.preventDefault();

const email = emailRef.current;
const password = passwordRef.current;

if(email !== null && password !== null) {
webAuth.signup({
connection: 'Username-Password-Authentication',
email: email.value,
password: password.value,
}, function(e) {
if(e) return console.log(e);
console.log(email + '\n' + password)
return alert('Success!');
}
)
}
}



return (

<div>
<div className='flex flex-col items-center justify-center w-screen h-screen px-8'>
<div className='text-2xl font-bold tracking-tight'>hi, welcome to placeholder</div>
<div className='h-px w-full bg-black mt-4'></div>
<div className='flex flex-col w-72 h-1/2'>
<div className='cursor-pointer flex flex-row items-center rounded-full mt-4 p-8 border-2 border-black w-full h-2'>
<svg xmlns="http://www.w3.org/2000/svg" height="1.5em" viewBox="0 0 488 512"><path d="M488 261.8C488 403.3 391.1 504 248 504 110.8 504 0 393.2 0 256S110.8 8 248 8c66.8 0 123 24.5 166.3 64.9l-67.5 64.9C258.5 52.6 94.3 116.6 94.3 256c0 86.5 69.1 156.6 153.7 156.6 98.2 0 135-70.4 140.8-106.9H248v-85.3h236.1c2.3 12.7 3.9 24.9 3.9 41.4z"/></svg>
<p className='ml-4 font-semibold'>Continue with Google</p>
</div>
<div className='cursor-pointer flex flex-row items-center rounded-full mt-4 p-8 border-2 border-black w-full h-2'>
<svg xmlns="http://www.w3.org/2000/svg" height="1.5em" viewBox="0 0 384 512"><path d="M318.7 268.7c-.2-36.7 16.4-64.4 50-84.8-18.8-26.9-47.2-41.7-84.7-44.6-35.5-2.8-74.3 20.7-88.5 20.7-15 0-49.4-19.7-76.4-19.7C63.3 141.2 4 184.8 4 273.5q0 39.3 14.4 81.2c12.8 36.7 59 126.7 107.2 125.2 25.2-.6 43-17.9 75.8-17.9 31.8 0 48.3 17.9 76.4 17.9 48.6-.7 90.4-82.5 102.6-119.3-65.2-30.7-61.7-90-61.7-91.9zm-56.6-164.2c27.3-32.4 24.8-61.9 24-72.5-24.1 1.4-52 16.4-67.9 34.9-17.5 19.8-27.8 44.3-25.6 71.9 26.1 2 49.9-11.4 69.5-34.3z"/></svg>
<p className='ml-4 font-semibold'>Continue with Apple</p>
</div>
<div className='text-center text-gray-500 my-4'>
or
</div>
<div className='font-bold text-lg'>
Sign up with your email address
</div>
<input type='email' name='email' placeholder='Enter your email.' ref={emailRef} className='signup-email rounded-md border-2 border-black w-76 h-12 pl-4 mt-4' />
<input type='password' name='password' placeholder='Create a password.' ref={passwordRef} className='signup-password rounded-md border-2 border-black w-76 h-12 pl-4 mt-4' />
</div>
<div onClick={handleSubmit} className='cursor-pointer flex flex-row items-center justify-center rounded-full mt-4 p-8 border-2 border-black w-48 h-2'>
<p className='font-semibold'>Sign Up</p>
</div>
</div>
</div>
)
}