Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matthewpereira
Copy link
Contributor

Playing with API Client management, but I'm not a pro engineer, so I might be doing this wrong.

Copy link

vercel bot commented Sep 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth0-b2b-saas-starter ❌ Failed (Inspect) Sep 23, 2024 6:41pm

@eatplaysleep
Copy link

You will also need to add the following to the createClientGrantArgs in scripts/bootstrap.mjs:

        ...,
        "create:users",
        // Add this
        "read:clients",
        "create:clients",
        "update:clients",
        "delete:clients",
        "create:client_keys",
        "read:client_keys",
        "update:client_keys",
        "delete:client_keys",
        "read:client_credentials",
        ...

@eatplaysleep
Copy link

Make sure to bump sonner to ^1.7.0

Copy link

@eatplaysleep eatplaysleep left a 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({

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.

Suggested change
const newClient = await managementClient.clients.create({
const { data: newClient } = await managementClient.clients.create({


revalidatePath("/dashboard/organization/api-clients")
return {
clientId: newClient.client_id!,

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.

Suggested change
clientId: newClient.client_id!,
clientId: newClient.client_id,

revalidatePath("/dashboard/organization/api-clients")
return {
clientId: newClient.client_id!,
clientSecret: newClient.client_secret!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { managementClient } from "@/lib/auth0"
import { managementClient } from "@/lib/auth0"
import { Client } from "@/lib/clients"

@@ -0,0 +1,135 @@
import { revalidatePath } from "next/cache"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { createApiClient } from "./actions"
import { createApiClient, CreateApiClientSuccess } from "./actions"

Comment on lines +35 to +44
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()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
})

Comment on lines +8 to +10
type CreateApiClientResult =
| { error: string }
| { clientId: string; clientSecret: string }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type CreateApiClientResult =
| { error: string }
| { clientId: string; clientSecret: string }
interface CreateApiClientError {
error: string
}
export interface CreateApiClientSuccess {
clientId: string
clientSecret: string
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants