auth: simplify admin login for local development
This commit is contained in:
parent
5264cccb6c
commit
bf42037619
3 changed files with 22 additions and 27 deletions
|
|
@ -2,7 +2,7 @@ import { Button } from "@minmon/ui/components/button";
|
||||||
import { Input } from "@minmon/ui/components/input";
|
import { Input } from "@minmon/ui/components/input";
|
||||||
import { Label } from "@minmon/ui/components/label";
|
import { Label } from "@minmon/ui/components/label";
|
||||||
import { useForm } from "@tanstack/react-form";
|
import { useForm } from "@tanstack/react-form";
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { Link, useNavigate } from "@tanstack/react-router";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { authClient } from "@/lib/auth-client";
|
||||||
|
|
||||||
import Loader from "./loader";
|
import Loader from "./loader";
|
||||||
|
|
||||||
export default function SignInForm({ onSwitchToSignUp }: { onSwitchToSignUp: () => void }) {
|
export default function SignInForm() {
|
||||||
const navigate = useNavigate({
|
const navigate = useNavigate({
|
||||||
from: "/",
|
from: "/",
|
||||||
});
|
});
|
||||||
|
|
@ -53,8 +53,14 @@ export default function SignInForm({ onSwitchToSignUp }: { onSwitchToSignUp: ()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full mt-10 max-w-md p-6">
|
<div className="mx-auto mt-10 grid w-full max-w-md gap-6 border bg-card p-6">
|
||||||
<h1 className="mb-6 text-center text-3xl font-bold">Welcome Back</h1>
|
<div className="space-y-2 text-center">
|
||||||
|
<p className="text-[11px] uppercase tracking-[0.24em] text-muted-foreground">Admin Access</p>
|
||||||
|
<h1 className="text-3xl font-bold tracking-tight">Sign in to minmon</h1>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Use your administrator account to open the protected monitoring dashboard.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
|
|
@ -78,7 +84,7 @@ export default function SignInForm({ onSwitchToSignUp }: { onSwitchToSignUp: ()
|
||||||
onChange={(e) => field.handleChange(e.target.value)}
|
onChange={(e) => field.handleChange(e.target.value)}
|
||||||
/>
|
/>
|
||||||
{field.state.meta.errors.map((error) => (
|
{field.state.meta.errors.map((error) => (
|
||||||
<p key={error?.message} className="text-red-500">
|
<p key={error?.message} className="text-xs text-red-500">
|
||||||
{error?.message}
|
{error?.message}
|
||||||
</p>
|
</p>
|
||||||
))}
|
))}
|
||||||
|
|
@ -101,7 +107,7 @@ export default function SignInForm({ onSwitchToSignUp }: { onSwitchToSignUp: ()
|
||||||
onChange={(e) => field.handleChange(e.target.value)}
|
onChange={(e) => field.handleChange(e.target.value)}
|
||||||
/>
|
/>
|
||||||
{field.state.meta.errors.map((error) => (
|
{field.state.meta.errors.map((error) => (
|
||||||
<p key={error?.message} className="text-red-500">
|
<p key={error?.message} className="text-xs text-red-500">
|
||||||
{error?.message}
|
{error?.message}
|
||||||
</p>
|
</p>
|
||||||
))}
|
))}
|
||||||
|
|
@ -121,14 +127,11 @@ export default function SignInForm({ onSwitchToSignUp }: { onSwitchToSignUp: ()
|
||||||
</form.Subscribe>
|
</form.Subscribe>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div className="mt-4 text-center">
|
<div className="grid gap-2 border-t pt-4 text-center text-xs text-muted-foreground">
|
||||||
<Button
|
<p>Student demo flow uses administrator sign-in only.</p>
|
||||||
variant="link"
|
<Link to="/" className="text-primary underline-offset-4 hover:underline">
|
||||||
onClick={onSwitchToSignUp}
|
Return to homepage
|
||||||
className="text-indigo-600 hover:text-indigo-800"
|
</Link>
|
||||||
>
|
|
||||||
Need an account? Sign Up
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,10 @@
|
||||||
import { createFileRoute } from "@tanstack/react-router";
|
|
||||||
import { useState } from "react";
|
|
||||||
|
|
||||||
import SignInForm from "@/components/sign-in-form";
|
import SignInForm from "@/components/sign-in-form";
|
||||||
import SignUpForm from "@/components/sign-up-form";
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
|
|
||||||
export const Route = createFileRoute("/login")({
|
export const Route = createFileRoute("/login")({
|
||||||
component: RouteComponent,
|
component: RouteComponent,
|
||||||
});
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
const [showSignIn, setShowSignIn] = useState(false);
|
return <SignInForm />;
|
||||||
|
|
||||||
return showSignIn ? (
|
|
||||||
<SignInForm onSwitchToSignUp={() => setShowSignIn(false)} />
|
|
||||||
) : (
|
|
||||||
<SignUpForm onSwitchToSignIn={() => setShowSignIn(true)} />
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||||
|
|
||||||
export function createAuth() {
|
export function createAuth() {
|
||||||
const db = createDb();
|
const db = createDb();
|
||||||
|
const isProduction = env.NODE_ENV === "production";
|
||||||
|
|
||||||
return betterAuth({
|
return betterAuth({
|
||||||
database: drizzleAdapter(db, {
|
database: drizzleAdapter(db, {
|
||||||
|
|
@ -21,8 +22,8 @@ export function createAuth() {
|
||||||
baseURL: env.BETTER_AUTH_URL,
|
baseURL: env.BETTER_AUTH_URL,
|
||||||
advanced: {
|
advanced: {
|
||||||
defaultCookieAttributes: {
|
defaultCookieAttributes: {
|
||||||
sameSite: "none",
|
sameSite: isProduction ? "none" : "lax",
|
||||||
secure: true,
|
secure: isProduction,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue