Init engine

When AppShell mounts, the Init engine starts the other engines in a fixed order. An app almost never calls it itself.

What it does
Starts the other engines when AppShell mounts, in a fixed order, and applies the preferences of the account after sign-in.
Exported from the package?
No. init and afterIdentityInit are not exported: they run inside AppShell, and you cannot import them. Pass disableInit to AppShell only when you start the engines yourself.

Which one do I use?

What I needUse
Start all engines for an appAppShell
Know what happens when the app startsinit
Know what happens after someone signed inafterIdentityInit

init

typescript
typescript
// Not exported: AppShell calls it when it mounts
async function init<T extends string>(paraglideRuntime: ParaglideRuntimeType<T>): Promise<void>

init(paraglideRuntime) is called by AppShell when it mounts. In this order it starts the Status engine, writes the version to the console, runs initAppState of the App state engine, sets the theme from the theme_cache cookie (a new cookie with system when there is none), calls createTranslationEngine of the Translation engine and picks the language, and starts the Identity engine, which asks the backend for the session.

When to use

Nothing: wrap your app in AppShell and pass paraglideRuntime.

When not to use, and what to use instead

Do not try to call it: it is not exported. Use disableInit on AppShell only when you start the engines yourself, for instance on a page without AppShell. Without init the engines keep their defaults and no one checks the session.

Live example

Checking the session…
CallResult
appState.tabIDnone
currentTheme.themeNamelight
currentLocale.valueen-us
authState.loadingtrue
authState.isLoggedInfalse

These values are what `init` set up for this page. Signed out, the language and theme come from the cookies or the browser, and `authState.isLoggedIn` stays false.

svelte
svelte
<AppShell {paraglideRuntime} appName="My app" shortAppName="App">
	{@render children()}
</AppShell>

<!-- Only when you start the engines yourself: -->
<AppShell paraglideRuntime={null} disableInit appName="My app" shortAppName="App">
	{@render children()}
</AppShell>

afterIdentityInit

typescript
typescript
// Not exported: the identity engine calls it after it found a session
async function afterIdentityInit(): Promise<void>

afterIdentityInit() runs when the Identity engine found a session and loaded the profile. It does nothing when no one is signed in. Signed in, it applies the preferences of the account: the date order, the first day of the week, the language (only when it differs from the cookie), the theme, the timezone and the consents. Then it runs the check of the Legal engine.

When to use

Nothing: the Identity engine calls it. It is why a signed-in person sees the language and theme of the account, also when this browser had other cookies.

When not to use, and what to use instead

It is not exported, so you cannot call it. To change a preference from your app use setTheme of the Theme engine or setLanguage of the Translation engine: they only change this browser, and saving to the account is for the settings screen.

Live example

Checking the session…

You are signed out, so `afterIdentityInit` did nothing: the language and theme here come from the cookies and the browser.

typescript
typescript
// Inside the identity engine, after a session was found:
await syncProfileData();
await afterIdentityInit();