mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
Improved signin flow
This commit is contained in:
parent
ad1f302ed3
commit
23bdf623b6
@ -1,6 +1,3 @@
|
||||
import { deprecatedSmartRouteHandler } from "@/lib/route-handlers";
|
||||
import { redirect } from "next/navigation";
|
||||
import { redirectHandler } from "@/lib/route-handlers";
|
||||
|
||||
export const GET = deprecatedSmartRouteHandler(async () => {
|
||||
redirect("/dashboard/auth/users");
|
||||
});
|
||||
export const GET = redirectHandler("users");
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
import { redirectHandler } from "@/lib/route-handlers";
|
||||
|
||||
export const GET = redirectHandler("auth");
|
||||
@ -1,6 +1,3 @@
|
||||
import { deprecatedSmartRouteHandler } from "@/lib/route-handlers";
|
||||
import { redirect } from "next/navigation";
|
||||
import { redirectHandler } from "@/lib/route-handlers";
|
||||
|
||||
export const GET = deprecatedSmartRouteHandler(async () => {
|
||||
redirect("/dashboard/settings/api-keys");
|
||||
});
|
||||
export const GET = redirectHandler("api-keys");
|
||||
|
||||
@ -8,8 +8,9 @@ import { Dialog } from "@/components/dialog";
|
||||
import { Paragraph } from "@/components/paragraph";
|
||||
import { SmartLink } from "@/components/smart-link";
|
||||
import { useFromNow } from "@/hooks/use-from-now";
|
||||
import { runAsynchronously } from "@stackframe/stack-shared/dist/utils/promises";
|
||||
import { neverResolve, runAsynchronously } from "@stackframe/stack-shared/dist/utils/promises";
|
||||
import { Project } from "@stackframe/stack/dist/lib/stack-app";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
|
||||
export default function ProjectsPageClient() {
|
||||
@ -17,7 +18,7 @@ export default function ProjectsPageClient() {
|
||||
|
||||
const projects = stackApp.useOwnedProjects();
|
||||
|
||||
const [createDialogOpen, setCreateDialogOpen] = useState(false);
|
||||
const [createDialogOpen, setCreateDialogOpen] = useState(projects.length === 0);
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -59,7 +60,7 @@ function ProjectCard(props: {
|
||||
};
|
||||
|
||||
return (
|
||||
<SmartLink href={`/projects/${encodeURIComponent(props.project.id)}/auth/users`} sx={{ color: "inherit" }}>
|
||||
<SmartLink href={`/projects/${encodeURIComponent(props.project.id)}`} sx={{ color: "inherit" }}>
|
||||
<Card variant="outlined">
|
||||
<CardContent>
|
||||
<Typography level="title-md" sx={singleLineCss}>{props.project.displayName}</Typography>
|
||||
@ -87,6 +88,7 @@ function CreateProjectDialog(props: { open: boolean, onClose(): void }) {
|
||||
const formId = useId();
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const stackApp = useStackApp({ projectIdMustMatch: "internal" });
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
@ -114,12 +116,12 @@ function CreateProjectDialog(props: { open: boolean, onClose(): void }) {
|
||||
setIsCreating(true);
|
||||
try {
|
||||
const formData = new FormData(event.currentTarget);
|
||||
await stackApp.createProject({
|
||||
const project = await stackApp.createProject({
|
||||
displayName: `${formData.get('name')}`,
|
||||
description: `${formData.get('description')}`,
|
||||
});
|
||||
|
||||
props.onClose();
|
||||
router.push(`/projects/${encodeURIComponent(project.id)}`);
|
||||
await neverResolve();
|
||||
} finally {
|
||||
setIsCreating(false);
|
||||
}
|
||||
|
||||
@ -325,3 +325,32 @@ export function smartRouteHandler<
|
||||
return await createResponse(req, requestId, smartRes, handler.response);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function redirectHandler(redirectPath: string, statusCode: 301 | 302 | 303 | 307 | 308 = 307): (req: NextRequest, options: any) => Promise<Response> {
|
||||
return smartRouteHandler({
|
||||
request: yup.object({
|
||||
url: yup.string().required(),
|
||||
method: yup.string().oneOf(["GET"]).required(),
|
||||
}),
|
||||
response: yup.object({
|
||||
statusCode: yup.number().oneOf([301, 302, 303, 307, 308]).required(),
|
||||
headers: yup.object().shape({
|
||||
location: yup.array(yup.string().required()),
|
||||
}),
|
||||
bodyType: yup.string().oneOf(["text"]).required(),
|
||||
body: yup.string().required(),
|
||||
}),
|
||||
async handler(req) {
|
||||
const newUrl = new URL(redirectPath, req.url + "/");
|
||||
return {
|
||||
statusCode,
|
||||
headers: {
|
||||
location: [newUrl.toString()],
|
||||
},
|
||||
bodyType: "text",
|
||||
body: "Redirecting...",
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user