Routing to Private Content
You can deep-link to anything in your app — private posts, gated dashboards, user-specific records, paywalled articles, multi-tenant resources. Ulinkly resolves the link to a destination; your app decides who's allowed to see it.
TL;DR
The pattern in one snippet — receive the link, check auth, render or deflect:
- Swift
- Kotlin
- Dart
- TypeScript (React Native)
ulink.dynamicLinkStream.sink { data in
guard let route = data.parameters?["route"] as? String else { return }
if AuthService.shared.isSignedIn, PermissionService.shared.canView(route) {
navigate(to: route)
} else {
presentSignIn(thenResumeTo: route)
}
}.store(in: &cancellables)
ulink.dynamicLinkStream.collect { data ->
val route = (data.parameters as? JsonObject)?.get("route")?.jsonPrimitive?.contentOrNull ?: return@collect
when {
!authService.isSignedIn() -> presentSignIn(targetRoute = route)
!permissionService.canView(route) -> showNotAuthorized()
else -> navigateTo(route)
}
}
ULink.instance.onLink.listen((data) {
final route = data.parameters?['route'] as String?;
if (route == null) return;
if (auth.isSignedIn && permissions.canView(route)) {
router.go('/$route');
} else {
router.go('/sign-in', extra: {'redirectTo': route});
}
});
ULink.onDynamicLink((data) => {
const route = data.parameters?.route;
if (typeof route !== 'string') return;
if (auth.isSignedIn && permissions.canView(route)) {
navigateTo(route);
} else {
navigateToSignIn(route);
}
});
In the Swift and Kotlin samples, ulink is the instance returned by ULink.initialize (on Android, ULink.getInstance()). The Kotlin samples read parameters as JSON, so they need kotlinx.serialization.json.JsonObject, jsonPrimitive and contentOrNull imports. The link must be a dynamic link that carries a route parameter; see Create the link.
That's the pattern. The rest of this page explains why it works, the step-by-step, and the rough edges.
The core idea: Ulinkly routes, your app authorizes
Ulinkly is the routing layer. Your app is the authorization layer. The two are deliberately separate.
When a user taps a deep link, Ulinkly resolves it to a destination inside your app — typically an in-app route like post/abc123 that you store in the link's parameters. Ulinkly doesn't know whether the user is signed in, who they are, or what they're allowed to see. It hands the destination to your app, and your app applies whatever auth and permission rules you've already built.
This is a feature, not a workaround. We don't ship a "Ulinkly-style auth" because every team brings their own — Firebase Auth, Supabase, Clerk, Auth0, Cognito, a custom JWT service. An opinionated integration would force you to give up choices that are usually deeply embedded in your app. By staying auth-agnostic, Ulinkly composes cleanly with whatever you already have.
The pattern, step by step
1. Create the link
When you create the link, use a dynamic link and put the in-app destination (a route or path your app already knows how to render) in its parameters. Don't put user IDs, session tokens, or sensitive data in the URL itself.
- Swift
- Kotlin
- Dart
- TypeScript (React Native)
- REST
let params = ULinkParameters.dynamic(
domain: "links.acme.com",
slug: "postabc123",
iosFallbackUrl: "https://apps.apple.com/app/acme/id0000000000",
androidFallbackUrl: "https://play.google.com/store/apps/details?id=com.acme",
fallbackUrl: "https://acme.com/p/abc123",
parameters: ["route": "post/abc123"]
)
let response = try await ulink.createLink(parameters: params)
val params = ULinkParameters.dynamic(
domain = "links.acme.com",
slug = "postabc123",
iosFallbackUrl = "https://apps.apple.com/app/acme/id0000000000",
androidFallbackUrl = "https://play.google.com/store/apps/details?id=com.acme",
fallbackUrl = "https://acme.com/p/abc123",
parameters = mapOf("route" to "post/abc123")
)
val response = ulink.createLink(params)
final params = ULinkParameters.dynamic(
domain: 'links.acme.com',
slug: 'postabc123',
iosFallbackUrl: 'https://apps.apple.com/app/acme/id0000000000',
androidFallbackUrl: 'https://play.google.com/store/apps/details?id=com.acme',
fallbackUrl: 'https://acme.com/p/abc123',
parameters: {'route': 'post/abc123'},
);
final response = await ULink.instance.createLink(params);
const response = await ULink.createLink({
domain: 'links.acme.com',
type: 'dynamic',
slug: 'postabc123',
iosFallbackUrl: 'https://apps.apple.com/app/acme/id0000000000',
androidFallbackUrl: 'https://play.google.com/store/apps/details?id=com.acme',
fallbackUrl: 'https://acme.com/p/abc123',
parameters: { route: 'post/abc123' },
});
curl -X POST https://api.ulink.ly/v1/sdk/links \
-H "X-App-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "dynamic",
"domain": "links.acme.com",
"slug": "postabc123",
"iosFallbackUrl": "https://apps.apple.com/app/acme/id0000000000",
"androidFallbackUrl": "https://play.google.com/store/apps/details?id=com.acme",
"fallbackUrl": "https://acme.com/p/abc123",
"parameters": { "route": "post/abc123" }
}'
The app opens the link through the project's deep linking scheme and receives the link's parameters. Route on a parameter such as route, not on the slug: the slug is the short URL's ID, and Ulinkly generates one if you don't set it.
2. Receive the link in your app
Your platform-specific deep-link handler receives the destination from Ulinkly. See the platform guides (iOS, Android, Flutter, React Native) for the wiring.
3. Check auth and authorize
Before rendering, run your normal auth and permission checks:
- Swift
- Kotlin
- Dart
- TypeScript (React Native)
ulink.dynamicLinkStream.sink { data in
guard let route = data.parameters?["route"] as? String else { return }
switch (AuthService.shared.isSignedIn, PermissionService.shared.canView(route)) {
case (false, _): deflectToSignIn(targetRoute: route)
case (true, false): showNotAuthorized()
case (true, true): navigate(to: route)
}
}.store(in: &cancellables)
ulink.dynamicLinkStream.collect { data ->
val route = (data.parameters as? JsonObject)?.get("route")?.jsonPrimitive?.contentOrNull ?: return@collect
when {
!authService.isSignedIn() -> deflectToSignIn(targetRoute = route)
!permissionService.canView(route) -> showNotAuthorized()
else -> navigateTo(route)
}
}
ULink.instance.onLink.listen((data) {
final route = data.parameters?['route'] as String?;
if (route == null) return;
if (!auth.isSignedIn) {
deflectToSignIn(targetRoute: route);
} else if (!permissions.canView(route)) {
showNotAuthorized();
} else {
navigateTo(route);
}
});
ULink.onDynamicLink((data) => {
const route = data.parameters?.route;
if (typeof route !== 'string') return;
if (!auth.isSignedIn) {
deflectToSignIn(route);
} else if (!permissions.canView(route)) {
showNotAuthorized();
} else {
navigateTo(route);
}
});
The check can be as simple as "is the user signed in" or as rich as a full RBAC/ABAC evaluation. Ulinkly doesn't care.
4. Render or deflect
If access is granted, render the destination. If not, deflect to sign-in, paywall, request-access, or whatever your product does for unauthorized users.
Handling the "user isn't signed in" case
This is the most common rough edge. The user opens a link, your app launches, and the user isn't authenticated. Two patterns work well.
Defer the destination in app state. Store the pending route somewhere (a singleton, persistent storage, or your state management layer) and replay it after sign-in completes.
- Swift
- Kotlin
- Dart
- TypeScript (React Native)
final class DeepLinkRouter {
static let shared = DeepLinkRouter()
private var pending: String?
func handle(_ route: String) {
if AuthService.shared.isSignedIn {
navigate(to: route)
} else {
pending = route
AuthService.shared.presentSignIn { [weak self] in
if let s = self?.pending { self?.navigate(to: s); self?.pending = nil }
}
}
}
}
object DeepLinkRouter {
private var pending: String? = null
fun handle(route: String) {
if (AuthService.isSignedIn()) {
navigateTo(route)
} else {
pending = route
AuthService.presentSignIn {
pending?.let { navigateTo(it); pending = null }
}
}
}
}
class DeepLinkRouter {
static String? _pending;
static void handle(String route) {
if (auth.isSignedIn) {
navigateTo(route);
} else {
_pending = route;
auth.presentSignIn().then((_) {
final s = _pending;
if (s != null) { navigateTo(s); _pending = null; }
});
}
}
}
let pending: string | null = null;
export function handleDeepLink(route: string) {
if (auth.isSignedIn) {
navigateTo(route);
} else {
pending = route;
auth.presentSignIn().then(() => {
if (pending) { navigateTo(pending); pending = null; }
});
}
}
Use deferred deep linking for the install case. When the link is tapped by someone who doesn't have your app installed, Ulinkly can preserve the destination across the install → first-launch boundary. See the platform guides for the deferred-link APIs.
What NOT to put in the URL
The URL is visible to anyone who has the link, plus anyone who scrapes referer headers, social previews, or share-sheet captures. Treat it as public even when the destination is private.
| Don't | Use instead |
|---|---|
| User IDs, account numbers | Opaque slugs (abc123) generated server-side |
| Session tokens, API keys | Standard auth headers / cookies in your app |
| PII (email, phone, SSN) | An in-app fetch keyed on the route, after auth |
| Payment / order details | A record ID; fetch the rest after auth |
Treat parameters (including route) as visible: anyone with the link can resolve it.
Vertical examples
The pattern is identical across verticals; only the auth check differs.
- B2B SaaS — a shared dashboard link. Your app checks that the recipient is on the workspace and has read permission for the dashboard.
- Social network — a profile or post link. Your app checks visibility (public / followers-only / private) against the viewer's relationship.
- Fintech — a transaction or invoice link. Your app re-authenticates with biometrics, then checks that the recipient owns the record. See Fintech use cases for the security framing.
- Healthcare — a patient record or appointment link. Your app checks that the signed-in user is allowed to see that record. See Health use cases.
- E-commerce — a wishlist or cart-share link. Your app checks whether the resource was set to "shareable" by the owner, and applies any rate limits.
- Education — a course module or assignment link. Your app checks enrollment, cohort, and unlock state.
In every case Ulinkly does the same thing: resolve the link, hand off the destination. The differences live entirely on your side, where they should.
Related
- Idempotent Link Creation — avoid creating duplicate links when the same share button is tapped multiple times
- Receive Links: iOS, Android, Flutter, React Native
- REST API Overview