Skip to content

Commit

Permalink
feat: Improve DX for self-hosted use-cases (#171)
Browse files Browse the repository at this point in the history
* feat: Improve DX for self-hosted use-cases

* switch to advanced.selfhosted

* selfhosted -> self_hosted
  • Loading branch information
m1guelpf authored Dec 9, 2023
1 parent b49a58c commit a6a5efd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/with-next/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { IDKitWidget } from '@worldcoin/idkit'
import { GetServerSideProps, InferGetServerSidePropsType } from 'next'

export const getServerSideProps = (async context => {
return { props: { app_id: context.query.app_id?.toString() || 'app_staging_45068dca85829d2fd90e2dd6f0bff997' } }
return { props: { app_id: context.query.app_id?.toString() as `app_${string}` || 'app_staging_45068dca85829d2fd90e2dd6f0bff997' } }
}) satisfies GetServerSideProps<{
app_id: string
app_id: `app_${string}`
}>

const Home = ({ app_id }: InferGetServerSidePropsType<typeof getServerSideProps>) => (
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export enum CredentialType {

export type IDKitConfig = {
/** Unique identifier for the app verifying the action. This should be the app ID obtained from the Developer Portal. */
app_id: string
app_id: `app_${string}`
/** The description of the specific action (shown to users in World App). Only recommended for actions created on-the-fly. */
action_description?: string
/** Encodes data into a proof that must match when validating. Read more on the [On-chain section](https://docs.worldcoin.org/advanced/on-chain). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const WorldIDState = () => {
} = useIDKitStore(getOptions, shallow)

const { connectorURI, reset, errorCode, result, verificationState } = useWorldBridge(
app_id,
app_id as `app_${string}`,
action,
signal,
bridge_url,
Expand Down
9 changes: 6 additions & 3 deletions packages/react/src/store/idkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {
type ISuccessResult,
} from '@worldcoin/idkit-core'

const SELF_HOSTED_APP_ID = 'self_hosted'

export type IDKitStore = {
app_id: IDKitConfig['app_id']
app_id: IDKitConfig['app_id'] | typeof SELF_HOSTED_APP_ID | ''
action: IDKitConfig['action']
signal: IDKitConfig['signal']
bridge_url?: IDKitConfig['bridge_url']
Expand Down Expand Up @@ -116,6 +118,7 @@ const useIDKitStore = createWithEqualityFn<IDKitStore>()(
bridge_url,
autoClose,
theme,
advanced,
}: Config,
source: ConfigSource
) => {
Expand All @@ -126,11 +129,11 @@ const useIDKitStore = createWithEqualityFn<IDKitStore>()(
theme,
signal,
action,
app_id,
autoClose,
bridge_url,
credential_types: sanitizedCredentialTypes.length ? sanitizedCredentialTypes : DEFAULT_CREDENTIAL_TYPES,
action_description,
credential_types: sanitizedCredentialTypes.length ? sanitizedCredentialTypes : DEFAULT_CREDENTIAL_TYPES,
app_id: advanced?.self_hosted ? SELF_HOSTED_APP_ID : app_id,
})

get().addSuccessCallback(onSuccess, source)
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export type WidgetConfig = {
onError?: CallbackFn<IErrorState>
}

export type Config = IDKitConfig & Required<Pick<IDKitConfig, 'action'>> & WidgetConfig
export type Config = Required<Pick<IDKitConfig, 'action'>> &
WidgetConfig &
((Exclude<IDKitConfig, 'app_id'> & { advanced: { self_hosted: true } }) | (IDKitConfig & { advanced?: { self_hosted?: false } }))

export type WidgetProps = Config & {
children?: ({ open }: { open: () => void }) => JSX.Element
Expand Down

0 comments on commit a6a5efd

Please sign in to comment.