WIP client management. Needs typescript work. - #57
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
You will also need to add the following to the |
|
Make sure to bump |
eatplaysleep
left a comment
There was a problem hiding this comment.
I think I got everything here. Just a few changes and I think it's good.
| } | ||
|
|
||
| try { | ||
| const newClient = await managementClient.clients.create({ |
There was a problem hiding this comment.
managementClient responses have a data object containing the actual response.
| const newClient = await managementClient.clients.create({ | |
| const { data: newClient } = await managementClient.clients.create({ |
|
|
||
| revalidatePath("/dashboard/organization/api-clients") | ||
| return { | ||
| clientId: newClient.client_id!, |
There was a problem hiding this comment.
unnecessary once you get the response object corrected.
| clientId: newClient.client_id!, | |
| clientId: newClient.client_id, |
| revalidatePath("/dashboard/organization/api-clients") | ||
| return { | ||
| clientId: newClient.client_id!, | ||
| clientSecret: newClient.client_secret! |
There was a problem hiding this comment.
| clientSecret: newClient.client_secret! | |
| clientSecret: newClient.client_secret |
| export const rotateApiClientSecret = withServerActionAuth( | ||
| async function rotateApiClientSecret(clientId: string, session: Session) { | ||
| try { | ||
| const result = await managementClient.clients.rotateSecret({ client_id: clientId }) |
There was a problem hiding this comment.
| const result = await managementClient.clients.rotateSecret({ client_id: clientId }) | |
| const { data: result } = await managementClient.clients.rotateClientSecret({ client_id }) |
| import { Session } from "@auth0/nextjs-auth0" | ||
| import { ClientCreateAppTypeEnum } from "auth0" | ||
|
|
||
| import { managementClient } from "@/lib/auth0" |
There was a problem hiding this comment.
| import { managementClient } from "@/lib/auth0" | |
| import { managementClient } from "@/lib/auth0" | |
| import { Client } from "@/lib/clients" |
| @@ -0,0 +1,135 @@ | |||
| import { revalidatePath } from "next/cache" | |||
There was a problem hiding this comment.
| import { revalidatePath } from "next/cache" | |
| "use server" | |
| import { revalidatePath } from "next/cache" |
| } from "@/components/ui/select" | ||
| import { SubmitButton } from "@/components/submit-button" | ||
|
|
||
| import { createApiClient } from "./actions" |
There was a problem hiding this comment.
| import { createApiClient } from "./actions" | |
| import { createApiClient, CreateApiClientSuccess } from "./actions" |
| const result = await createApiClient(formData) | ||
|
|
||
| if ('error' in result) { | ||
| toast.error(result.error) | ||
| } else { | ||
| toast.success(`API Client created: ${formData.get("name")}`) | ||
| toast.info(`Client ID: ${result.clientId}`) | ||
| toast.info(`Client Secret: ${result.clientSecret}`) | ||
| ref.current?.reset() | ||
| } |
There was a problem hiding this comment.
| const result = await createApiClient(formData) | |
| if ('error' in result) { | |
| toast.error(result.error) | |
| } else { | |
| toast.success(`API Client created: ${formData.get("name")}`) | |
| toast.info(`Client ID: ${result.clientId}`) | |
| toast.info(`Client Secret: ${result.clientSecret}`) | |
| ref.current?.reset() | |
| } | |
| toast.promise(createApiClient(formData), { | |
| loading: "Creating client...", | |
| success: (result) => { | |
| if ("error" in result) { | |
| throw result.error | |
| } | |
| toast(() => <h5>Your client secret is:</h5>, { | |
| description: () => ( | |
| <code> | |
| { | |
| (result as unknown as CreateApiClientSuccess) | |
| ?.clientSecret | |
| } | |
| </code> | |
| ), | |
| duration: Infinity, | |
| action: { | |
| label: "Dismiss", | |
| onClick: () => {}, | |
| }, | |
| }) | |
| return `API Client created: ${formData.get("name")}` | |
| }, | |
| error: (err) => err, | |
| }) |
| type CreateApiClientResult = | ||
| | { error: string } | ||
| | { clientId: string; clientSecret: string } |
There was a problem hiding this comment.
| type CreateApiClientResult = | |
| | { error: string } | |
| | { clientId: string; clientSecret: string } | |
| interface CreateApiClientError { | |
| error: string | |
| } | |
| export interface CreateApiClientSuccess { | |
| clientId: string | |
| clientSecret: string | |
| } |
There was a problem hiding this comment.
Just realized this is not used. Remove it entirely.
Playing with API Client management, but I'm not a pro engineer, so I might be doing this wrong.