Created
October 5, 2023 22:11
-
-
Save sheppardjm/67339bd2565e507d21c5fb6df7082686 to your computer and use it in GitHub Desktop.
Add a new Kinde organization in server components using Nextjs server actions
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
"use server"; | |
import { redirect } from "next/navigation"; | |
export async function createOrgAction(formData: FormData) { | |
const org = formData.get("org"); | |
redirect(`/organization/${org}`); | |
} |
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
/** @type {import("next").NextConfig} */ | |
const config = { | |
... | |
experimental: { | |
serverActions: true, | |
}, | |
}; | |
export default config; |
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
import { CreateOrgLink } from "@kinde-oss/kinde-auth-nextjs/server"; | |
export default function Page({ params: { org } }: { params: { org: string } }) { | |
return ( | |
<div> | |
<h1>{org}</h1> | |
<CreateOrgLink orgName={org}>Create Organization</CreateOrgLink> | |
</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
import { OrgInput } from "./orgInput"; | |
export default function Page() { | |
return ( | |
<> | |
<OrgInput /> | |
</> | |
); | |
} |
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
"use client"; | |
import { useState } from "react"; | |
import { createOrgAction } from "../actions"; | |
export const OrgInput = () => { | |
const [org, setOrg] = useState(null); | |
return ( | |
<> | |
<form action={createOrgAction}> | |
<input | |
type="text" | |
placeholder="Organization Name" | |
name="org" | |
onChange={(e) => setOrg(e.target.value)} | |
/> | |
<button type="submit">Create Organization</button> | |
</form> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment