-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
505 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { setupAuth } from "@/lib/auth"; | ||
import type { Context, Next } from "hono"; | ||
import { createMiddleware } from "hono/factory"; | ||
|
||
export const sessionMiddleware = async (c: Context, next: Next) => { | ||
export const sessionMiddleware = createMiddleware(async (c, next) => { | ||
const auth = setupAuth(c); | ||
const session = await auth.api.getSession({ headers: c.req.raw.headers }); | ||
const headers = new Headers(c.req.raw.headers); | ||
const session = await auth.api.getSession({ headers }); | ||
|
||
if (!session) { | ||
c.set("user", null); | ||
c.set("session", null); | ||
return next(); | ||
return await next(); | ||
} | ||
|
||
c.set("user", session.user); | ||
c.set("session", session.session); | ||
|
||
return next(); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import Login from "@/components/login"; | ||
|
||
export default function Page() { | ||
return <Login />; | ||
return ( | ||
<div className="min-h-screen flex items-center justify-center max-w-md mx-auto"> | ||
<Login /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,77 @@ | ||
"use client"; | ||
|
||
import { authClient } from "@/lib/auth"; | ||
import Link from "next/link"; | ||
import { useState } from "react"; | ||
import { Logo } from "./logo"; | ||
import { Button } from "./ui/button"; | ||
import { Input } from "./ui/input"; | ||
import { InputOTPGroup } from "./ui/input-otp"; | ||
import { InputOTP } from "./ui/input-otp"; | ||
import { InputOTPSlot } from "./ui/input-otp"; | ||
|
||
export default function Login() { | ||
const handleLogin = async () => { | ||
await authClient.emailOtp.sendVerificationOtp({ | ||
email: "[email protected]", | ||
email, | ||
type: "sign-in", | ||
}); | ||
}; | ||
|
||
const [email, setEmail] = useState(""); | ||
const [showOTP, setShowOTP] = useState(false); | ||
const [otp, setOtp] = useState(""); | ||
|
||
return ( | ||
<button onClick={handleLogin} type="button"> | ||
Login | ||
</button> | ||
<div className="flex flex-col gap-4 w-full"> | ||
<div className="mb-4"> | ||
<Link href="/"> | ||
<Logo /> | ||
</Link> | ||
</div> | ||
|
||
{!showOTP ? ( | ||
<form | ||
className="flex flex-col gap-4" | ||
onSubmit={async (e) => { | ||
e.preventDefault(); | ||
await handleLogin(); | ||
setShowOTP(true); | ||
}} | ||
> | ||
<Input | ||
type="email" | ||
placeholder="Email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
required | ||
/> | ||
<Button type="submit">Send code</Button> | ||
</form> | ||
) : ( | ||
<form | ||
className="flex flex-col gap-4" | ||
onSubmit={async (e) => { | ||
e.preventDefault(); | ||
await authClient.signIn.emailOtp({ | ||
email, | ||
otp, | ||
}); | ||
}} | ||
> | ||
<InputOTP maxLength={6} value={otp} onChange={setOtp}> | ||
<InputOTPGroup> | ||
<InputOTPSlot index={0} /> | ||
<InputOTPSlot index={1} /> | ||
<InputOTPSlot index={2} /> | ||
<InputOTPSlot index={3} /> | ||
<InputOTPSlot index={4} /> | ||
<InputOTPSlot index={5} /> | ||
</InputOTPGroup> | ||
</InputOTP> | ||
<Button type="submit">Sign in</Button> | ||
</form> | ||
)} | ||
</div> | ||
); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Slot } from "@radix-ui/react-slot"; | ||
import { type VariantProps, cva } from "class-variance-authority"; | ||
import * as React from "react"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
|
||
const buttonVariants = cva( | ||
"inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", | ||
{ | ||
variants: { | ||
variant: { | ||
default: "bg-primary text-primary-foreground hover:bg-primary/90", | ||
destructive: | ||
"bg-destructive text-destructive-foreground hover:bg-destructive/90", | ||
outline: | ||
"border border-input bg-background hover:bg-accent hover:text-accent-foreground", | ||
secondary: | ||
"bg-secondary text-secondary-foreground hover:bg-secondary/80", | ||
ghost: "hover:bg-accent hover:text-accent-foreground", | ||
link: "text-primary underline-offset-4 hover:underline", | ||
}, | ||
size: { | ||
default: "h-10 px-4 py-2", | ||
sm: "h-9 px-3", | ||
lg: "h-11 px-8", | ||
icon: "h-10 w-10", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
size: "default", | ||
}, | ||
}, | ||
); | ||
|
||
export interface ButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
VariantProps<typeof buttonVariants> { | ||
asChild?: boolean; | ||
} | ||
|
||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "button"; | ||
return ( | ||
<Comp | ||
className={cn(buttonVariants({ variant, size, className }))} | ||
ref={ref} | ||
{...props} | ||
/> | ||
); | ||
}, | ||
); | ||
Button.displayName = "Button"; | ||
|
||
export { Button, buttonVariants }; |
Oops, something went wrong.