In a React Native or Expo app, in-app feedback comes down to a short-lived token for the user your app already signed in (your server signs it, or your auth provider already issued it), a provider around your app that shows the feedback widget in a sheet, and a button that opens it. Your users then post, vote and comment as themselves, without a second account, and you know who asked for what. The examples use Swingback's React Native SDK, which runs in Expo Go.
What feedback in a mobile app should do#
A link to a feedback page in the phone's browser works, but it loses most people on the way:
- It asks them to sign in again. Your app knows who they are. A second login for the feedback tool is where most requests end.
- It leaves the app. A sheet over the screen they were on keeps them where the idea came from.
- It can't tell you who asked. Without a signed-in user, a request from your largest customer reads like one from a trial that ended last month.
There is one more constraint particular to mobile: every change to your app waits for a release and a store review. Whatever you show in the app should be able to change without one.
Why the SDK is a web view#
I built Swingback's mobile SDKs as shells around the widget your portal already serves: the same boards, votes,
comments, roadmap and changelog as on the web, in a sheet or a screen of your app. The React Native one is JavaScript
alone, on react-native-webview: it adds no native code of its own and needs no development build, since Expo Go
already has the web view it runs on.
That choice has a price: it's a web page in a native sheet, not native screens. What it buys is that everything the widget learns (a new page, a fix, a language) reaches every app the day it ships, without a release of yours. For a feedback board, which changes more often than the app around it, I think that's the right trade.
1. Sign tokens on your server, never in the app#
The identity secret that signs tokens can sign anyone in as any of your users. It can't sit in your app's code, and not
in an EXPO_PUBLIC_ variable either: Expo writes those into the JavaScript bundle that ships to every phone. It stays on
your server, which signs a token for the one user its session names, and only that token travels.
Your app already has an API it calls with the user's credential. One more endpoint there does it, here in Express, with the function that signs, which is short and needs no library:
// Behind the middleware that checks your app's own sign-in and sets req.user.
app.get("/feedback-token" , (req, res) => {
const token = req.user ? identityToken(req.user) : null;
res.set("Cache-Control", "no-store").json({ token });
});The endpoint decides who the token is for from the session alone. A token for a user id the request names would let anyone sign in as anyone.
On Firebase, Supabase, Clerk or Auth0, you may not need this endpoint at all: name the provider in your dashboard, under Settings → Sign-in, and the widget accepts the token your app already has, with no server and no secret (Apps without a server). Sign your own when you want the token to carry traits and companies.
2. Install the SDK#
npx expo install @swingback/react-native react-native-webviewWithout Expo, npm install the same two packages. The SDK needs React Native 0.76 or later with the New Architecture,
and react-native-webview 14 or later, which Expo Go has.
3. Wrap your app in the provider#
SwingbackProvider takes your portal's address and a function that gets the signed-in user's token from your server.
In an Expo app that keeps its session in the device's secure store:
// App.tsx
import { SwingbackProvider } from "@swingback/react-native" ;
import * as SecureStore from "expo-secure-store";
import { Navigation } from "./Navigation" ;
// The signed-in user's identity token, from your server; null for nobody.
async function feedbackToken(): Promise<string | null> {
const session = await SecureStore.getItemAsync("session");
if (!session) return null;
const response = await fetch("https://api.example.com/feedback-token" , {
headers: { Authorization: `Bearer ${session}` },
});
if (!response.ok) throw new Error(`The server answered ${response.status}`);
return ((await response.json()) as { token: string | null }).token;
}
export default function App() {
return (
<SwingbackProvider portal="https://feedback.example.com" token={feedbackToken}>
<Navigation />
</SwingbackProvider>
);
}The function is called each time the widget opens, so a token never has to outlive a few minutes. It returns null when
nobody is signed in, which ends the session of a user the widget had and keeps a guest's, and throws when it can't get a
token, say offline: the widget is then left as it was, and reports token_unavailable. With your auth provider's token
instead, the function returns that: with Firebase, (await getAuth().currentUser?.getIdToken()) ?? null.
4. Open it where people have ideas#
useSwingback() opens the sheet from any screen, on the page you name:
import { useSwingback } from "@swingback/react-native" ;
import { Button } from "react-native";
export function SettingsScreen() {
const swingback = useSwingback();
return (
<>
<Button title="Send feedback" onPress={() => swingback.open()} />
<Button title="What's new" onPress={() => swingback.open("changelog")} />
</>
);
}The sheet is a page sheet on iOS and the whole screen on Android, where the back button goes back in the widget first. A page is the feedback (the default), the roadmap, the changelog, a new post, or one post or board by its slug.
For the roadmap as a tab of its own, FeedbackWidget fills the place you give it, inside the provider:
import { FeedbackWidget } from "@swingback/react-native" ;
export function RoadmapScreen() {
return <FeedbackWidget page="roadmap" handlesBack style={{ flex: 1 }} />;
}5. Sign in and out with your app#
The widget keeps its session in the web view's storage, across launches. When your user signs out of your app, end the widget's session too, so that the next person on that phone isn't writing as them; when another user signs in, ask for their token:
await SecureStore.deleteItemAsync("session");
await swingback.logout(); // the widget's session ends with your app's
await swingback.identify(); // after your own sign-in: a widget on screen signs the new user in Before you ship it#
- Send what helps you rank requests. The token can carry traits, such as a plan, and the companies a user belongs to with what each is worth to you. Requests then rank by the value of the customers who asked: see Customers and companies.
- Decide where links go. Links that leave the widget open in the device's browser. The provider's
openUrlopens the sheet's links your own way, in an in-app browser for instance. AFeedbackWidgetscreen doesn't take that callback: its links still open in the browser. - Title the sheet, or drop its bar. The sheet's title is the portal's word for the widget, in your reader's
language. The provider's
titlesets your own, ornullnone, andshowsBar={false}leaves the bar out. - Listen if you need to.
swingback.on()tells you when the widget is ready, when your user is signed in or out, and the code of an error, for your logs.
React Native in the docs has every option, and your dashboard gives the install steps with your portal's address filled in, under Settings → Widget → Install. For a web app, the Next.js version of this post builds the same flow by hand.
