Quickstart — JavaScript
Add HelloJohn authentication to any JavaScript app — Vanilla JS, Svelte, SolidJS, Astro, or any framework not covered by a dedicated SDK.
Time: ~10 minutes Prerequisites: A HelloJohn account (Cloud) or a self-hosted server running locally.
Install the SDK
npm install @hellojohn/jsyarn add @hellojohn/jspnpm add @hellojohn/js<script src="https://cdn.hellojohn.dev/js/v1/hellojohn.min.js"></script>Initialize the client
import { HelloJohn } from '@hellojohn/js'
export const hellojohn = new HelloJohn({
publishableKey: 'pk_live_XXXXXXXXXXXXXXXX',
})Only use your Publishable Key (pk_...) in browser code. Never include your Secret Key in client-side JavaScript.
Mount the sign-in form
Render the hosted sign-in UI into any DOM element:
import { hellojohn } from '../lib/hellojohn'
const container = document.getElementById('sign-in-container')!
hellojohn.mountSignIn(container, {
redirectUrl: '/dashboard',
})<div id="sign-in-container"></div>
<script type="module" src="/src/pages/sign-in.ts"></script>Check if the user is signed in
import { hellojohn } from '../lib/hellojohn'
async function init() {
const session = await hellojohn.getSession()
if (!session) {
window.location.href = '/sign-in'
return
}
const user = session.user
document.getElementById('greeting')!.textContent = `Welcome, ${user.name}!`
}
init()Listen for auth state changes
React to sign-in and sign-out events:
import { hellojohn } from './hellojohn'
hellojohn.addListener('session', (session) => {
if (session) {
console.log('Signed in:', session.user.email)
showDashboard()
} else {
console.log('Signed out')
showSignIn()
}
})Get the token for API calls
import { hellojohn } from './hellojohn'
export async function fetchWithAuth(url: string, init?: RequestInit) {
const token = await hellojohn.getToken()
return fetch(url, {
...init,
headers: {
...init?.headers,
Authorization: `Bearer ${token}`,
},
})
}Using with Svelte, SolidJS, or Astro
The @hellojohn/js SDK is framework-agnostic. You can wrap it in your framework's reactive primitives:
import { writable } from 'svelte/store'
import { hellojohn } from '$lib/hellojohn'
export const session = writable(null)
hellojohn.addListener('session', (s) => session.set(s))import { createSignal } from 'solid-js'
import { hellojohn } from './hellojohn'
const [session, setSession] = createSignal(null)
hellojohn.addListener('session', setSession)
export { session }Next steps
Quickstart — React Native
Add HelloJohn authentication to your React Native app with Expo. Sign in, protect screens, and manage sessions with the useAuth hook.
Architecture Overview
HelloJohn's two-layer architecture — Control Plane and Data Plane — and how they work together to deliver multi-tenant authentication at any scale.