Popup Sign-In (Auth0 Lock-style)
Open a popup window for authentication. The user authenticates on
auth.zewstid.compostMessageSDK Version: Requires
v0.9.0+@zewstid/nextjs
When to Use Popup Sign-In
| Use Case | Recommended |
|---|---|
| User is filling a form and you don't want to lose state | Popup |
| SPA with complex client-side state | Popup |
| Simple login page | Redirect (simpler) |
| Mobile web | Redirect (popups blocked) |
Quick Start
1. Create the Popup Callback Page
// app/popup-callback/page.tsx import { PopupCallback } from '@zewstid/nextjs'; export default function PopupCallbackPage() { return <PopupCallback />; }
This page receives the OAuth callback inside the popup and relays the result to your parent window via
postMessage2. Add the PopupSignIn Button
'use client'; import { PopupSignIn } from '@zewstid/nextjs'; import { useRouter } from 'next/navigation'; export function LoginButton() { const router = useRouter(); return ( <PopupSignIn onSuccess={() => router.push('/dashboard')} onError={(err) => console.error('Auth failed:', err)} > Sign in with ZewstID </PopupSignIn> ); }
That's it. The button opens a popup, the user authenticates, the popup closes, and
onSuccessHow It Works
1. User clicks PopupSignIn button 2. Popup opens to auth.zewstid.com with ?display=popup 3. ZewstID renders compact login theme (no header/footer) 4. User authenticates (password, social, OTP, etc.) 5. ZewstID redirects to /popup-callback in the popup 6. PopupCallback sends postMessage to parent window 7. Popup auto-closes 8. Parent receives message, NextAuth session updates 9. onSuccess() fires in your app
API Reference
<PopupSignIn>
<PopupSignIn>| Prop | Type | Default | Description |
|---|---|---|---|
provider | string | "zewstid" | OAuth provider ID |
children | ReactNode | "Sign in with ZewstID" | Button content |
onSuccess | () => void | - | Called on successful auth |
onError | (error: string) => void | - | Called on auth failure |
callbackUrl | string | "/popup-callback" | Popup callback route |
popupWidth | number | 500 | Popup window width in px |
popupHeight | number | 700 | Popup window height in px |
className | string | - | CSS class (disables default styles) |
style | CSSProperties | - | Inline styles |
disabled | boolean | false | Disable the button |
<PopupCallback>
<PopupCallback>| Prop | Type | Default | Description |
|---|---|---|---|
successMessage | string | "Authentication successful! Closing window..." | Message on success |
notPopupMessage | string | "This page should be opened in a popup window." | Message when not in popup |
autoCloseDelay | number | 1500 | Delay before auto-close (ms) |
className | string | - | CSS class |
style | CSSProperties | - | Inline styles |
Popup Blocker Fallback
If the browser blocks the popup,
PopupSignInsignIn('zewstid')onError"Popup was blocked. Please allow popups for this site."Custom Styling
Pass a
classNameclassName<PopupSignIn className="btn btn-primary" onSuccess={handleSuccess}> Sign in </PopupSignIn>
Or use inline
style<PopupSignIn style={{ background: '#1a1a2e', borderRadius: '12px' }} onSuccess={handleSuccess} > Sign in </PopupSignIn>
Non-Next.js Apps
For React SPAs, Vue, Svelte, or other frameworks, use the standalone popup callback HTML served by the API Gateway at
https://api.zewstid.com/popup-callbackpostMessage// Open popup manually const popup = window.open( 'https://auth.zewstid.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=https://api.zewstid.com/popup-callback&response_type=code&scope=openid&display=popup', 'zewstid-signin', 'width=500,height=700' ); // Listen for result window.addEventListener('message', (event) => { if (event.data?.type === 'zewstid:auth:success') { // Exchange event.data.code for tokens } });
Was this page helpful?
Let us know how we can improve our documentation