-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP client management. Needs typescript work. #57
base: main
Are you sure you want to change the base?
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.