Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-parents-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/astro": patch
---

Add a reusable ID generation function
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ interface Props {
component: 'sign-in' | 'sign-up' | 'organization-list' | 'organization-profile' | 'organization-switcher' | 'user-button' | 'user-profile' | 'google-one-tap'
}

import { customAlphabet, urlAlphabet } from "nanoid";
import { generateSafeId } from '@clerk/astro/internal';

const safeId = customAlphabet(urlAlphabet, 10)();
const safeId = generateSafeId();

const { component, ...props } = Astro.props
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { HTMLTag, Polymorphic } from 'astro/types'
import type { SignInProps } from "@clerk/types";
type Props<Tag extends HTMLTag = HTMLTag> = Polymorphic<SignInProps & { as: Tag; mode?: 'redirect' | 'modal' }>

import { customAlphabet, urlAlphabet } from "nanoid";
import { generateSafeId } from '@clerk/astro/internal';
Comment thread
dimkl marked this conversation as resolved.

const safeId = customAlphabet(urlAlphabet, 10)();
const safeId = generateSafeId();

const {
as: Tag = 'button',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { HTMLTag, Polymorphic } from 'astro/types'
import type { SignOutOptions } from '@clerk/types';
type Props<Tag extends HTMLTag = HTMLTag> = Polymorphic<{ as: Tag; } & SignOutOptions>

import { customAlphabet, urlAlphabet } from "nanoid";
import { generateSafeId } from '@clerk/astro/internal';

const safeId = customAlphabet(urlAlphabet, 10)();
const safeId = generateSafeId();

const {
as: Tag = 'button',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { HTMLTag, Polymorphic } from 'astro/types'
import type { SignUpProps } from "@clerk/types";
type Props<Tag extends HTMLTag = HTMLTag> = Polymorphic<SignUpProps & { as: Tag; mode?: 'redirect' | 'modal' }>

import { customAlphabet, urlAlphabet } from "nanoid";
import { generateSafeId } from '@clerk/astro/internal';

const safeId = customAlphabet(urlAlphabet, 10)();
const safeId = generateSafeId();

const {
as: Tag = 'button',
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ import { createInjectionScriptRunner } from './create-injection-script-runner';
const runInjectionScript = createInjectionScriptRunner(createClerkInstance);

export { runInjectionScript };

export { generateSafeId } from './utils/generateSafeId';
10 changes: 10 additions & 0 deletions packages/astro/src/internal/utils/generateSafeId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { customAlphabet, urlAlphabet } from 'nanoid';

/**
* Generates a safe, URL-friendly unique identifier.
*
* @example
* const id = generateSafeId();
* console.log(id); // Outputs something like: "f3x2P9Xn1K"
*/
export const generateSafeId = (defaultSize = 10) => customAlphabet(urlAlphabet, defaultSize)();