Skip to main content
getSignInUrl generates a URL that redirects users to the WorkOS AuthKit sign-in page. This is typically used to create sign-in links or buttons in your application.

Usage

import { getSignInUrl } from '@workos-inc/authkit-nextjs';

const signInUrl = await getSignInUrl();

Signature

async function getSignInUrl(options?: {
  organizationId?: string;
  loginHint?: string;
  redirectUri?: string;
  prompt?: 'consent';
  state?: string;
  returnTo?: string;
}): Promise<string>

Parameters

options
object
Configuration options for the sign-in URL.

Returns

url
string
The complete URL to redirect the user to for signing in.

Examples

import Link from 'next/link';
import { getSignInUrl, withAuth } from '@workos-inc/authkit-nextjs';

export default async function HomePage() {
  const { user } = await withAuth();
  
  if (!user) {
    const signInUrl = await getSignInUrl();
    return <Link href={signInUrl}>Sign in</Link>;
  }
  
  return <div>Welcome back!</div>;
}

Pre-filling the email

import { getSignInUrl } from '@workos-inc/authkit-nextjs';

export default async function InvitePage({ email }: { email: string }) {
  const signInUrl = await getSignInUrl({
    loginHint: email,
  });
  
  return (
    <a href={signInUrl}>Sign in as {email}</a>
  );
}

Organization-specific sign-in

import { getSignInUrl } from '@workos-inc/authkit-nextjs';

export default async function OrgSignInPage({ orgId }: { orgId: string }) {
  const signInUrl = await getSignInUrl({
    organizationId: orgId,
  });
  
  return (
    <a href={signInUrl}>Sign in to your organization</a>
  );
}

Passing custom state

import { getSignInUrl } from '@workos-inc/authkit-nextjs';

export default async function PricingPage() {
  const signInUrl = await getSignInUrl({
    state: JSON.stringify({
      teamId: 'team_123',
      referrer: 'pricing-page',
      plan: 'pro',
    }),
  });
  
  return <a href={signInUrl}>Sign in to upgrade</a>;
}

Custom return path

import { getSignInUrl } from '@workos-inc/authkit-nextjs';

export default async function ProtectedPage() {
  const signInUrl = await getSignInUrl({
    returnTo: '/dashboard/settings',
  });
  
  return (
    <a href={signInUrl}>Sign in to access settings</a>
  );
}

Force re-authentication

import { getSignInUrl } from '@workos-inc/authkit-nextjs';

export default async function SecurityPage() {
  // Forces user to re-authenticate even if they have an active session
  const signInUrl = await getSignInUrl({
    prompt: 'consent',
  });
  
  return (
    <a href={signInUrl}>Verify your identity</a>
  );
}

Notes

  • The generated URL is specific to your WorkOS configuration and includes your client ID
  • Custom state is passed through the OAuth flow and available in the handleAuth callback
  • Use returnTo to send users back to a specific page after they sign in
  • The loginHint parameter improves UX by pre-filling the email field but doesn’t force authentication with that email

Build docs developers (and LLMs) love