Tie votes to your signed in users in Swift
How to sign users in with one call, what happens to their earlier votes and what you see as the owner.
Free for one project and 100 votes. Paid plans start with a 14 day trial, no card.
Guests
Nothing needs setting up. The first time the package needs a voter, it mints an anonymous one and keeps it between launches.
Without accounts, every device is its own voter.
For an app with no accounts, this is the right answer and the end of the subject.
A voter is minted by the first write, by a built in screen appearing, or by a call to me(), whichever happens first. There is nothing to call before a vote, so upvoting a feature works on a fresh install with no ceremony.
The anonymous voter is a token the device holds. The package keeps it in the keychain under the service com.votefirst.sdk, with the project as the account, so it survives launches and a write queued earlier can still go out.
The token is signed by the server for one project and no other. A token lifted from one board cannot be replayed against another.
let vote = try await VoteFirst.upvote(featureID: 21519)Why sign in
An anonymous voter belongs to whoever holds the token. Someone with an iPhone and an iPad, or a new phone, becomes a stranger each time.
A device is not a person, and your accounts are.
Signing in gives the vote an owner you can name.
If people are already signed in to your app, sign them in to the board too. Their votes then belong to them on every device, and the dashboard shows who asked for what instead of a generated handle.
It also joins your platforms. The same token identifies a person on your website and in your app, so a customer who votes in both places is one voter with one history.
Two of your own apps over the same project do not share an anonymous voter, because each keychain item belongs to the app that wrote it. Sign both in with your own ids and they become one person.
Your server
The token is a JWT that holds your user's id in sub and an expiry in exp. Name and email are optional extras.
Your server signs the token. The app only carries it.
The secret is never in the app, because anyone holding it can claim to be any of your users.
Generate the SSO secret under Share & Embed in your dashboard and keep it with your other server secrets. The server signs with it after your own login succeeds and sends the token to the app. A client that could name any user could vote as any user, which is why this is a token and not a user id argument.
Two claims are required. sub is your own id for the person, and the voter becomes sso_ followed by the project id and that sub. exp is the expiry, and a token without one is refused. On a phone a token can sit for months, so one that never expires would never stop working if it leaked.
name is what their comments are signed with, and email stays on their voter profile and is never published on the board. Sign with HS256, HS384 or HS512. The SSO guide has the server code in Node, Python and Go, and the Swift side is identical for all of them.
The call
After your login succeeds, ask your server for a token and pass it to the package. Run it on every launch, beside the place you restore your own session.
One call turns a guest into your user.
The sign in is held in memory, not stored, so it has to be repeated.
Because nothing is stored, a relaunched app is anonymous until signIn runs again. Put the call where you restore the session, and the person never notices the gap.
A refused token throws identityInvalid. The anonymous voter the device already had is still there, so the person can carry on taking part rather than being stranded. Catch the error, show nothing alarming and let them vote.
The error has a short list of causes. The token may have expired, the secret may differ from the dashboard, or the project owner may not be on a plan that includes single sign on.
import VoteFirst
func connectBoard(for session: Session) async {
do {
let token = try await api.voteFirstToken(session)
try await VoteFirst.signIn(ssoToken: token)
} catch {
print("Voting anonymously: \(error)")
}
}func disconnectBoard() async {
await VoteFirst.signOut()
}Earlier votes
Nothing already recorded moves. Votes made as a guest stay with the anonymous voter that cast them.
Votes cast before signing in stay where they were.
Plan for it by asking people to sign in before they vote, not after.
This surprises people, so decide for your app. If a guest votes on three features and then signs in, the signed in voter starts with a clean history, and the three votes remain on the guest voter on that phone.
Signing out drops the sign in and falls back to the device's anonymous voter, which is still there with its own history. Nothing is sent, and nothing moves back either.
If your app asks for an account early, the question rarely comes up. If it lets guests browse and vote first, tell them that signing in starts their votes fresh, or ask them to sign in at the moment they first want to vote.
Reading the voter
me() returns the voter, with its id, kind, display name and the features it has already voted for.
Ask who the voter is, and draw your screen from it.
Calling it on every launch renews the voter instead of replacing it.
The kind is either anonymous or sso, so a screen can show a gentle prompt to a guest and nothing to a person who is signed in. The voterID is what every vote of theirs is filed under, for example anon_ followed by a hash, or sso_42_user-9 for a signed in person.
A custom board draws its vote buttons from votedFeatureIDs on the first render. A page of features also carries hasVoted on each item, so you rarely need both, but the identity is one request where a whole board is several pages.
The banned field tells you whether the project has stopped the voter writing. Reading, voting and liking still work, while commenting and suggesting are refused. The built in screens replace the comment box and the suggestion form with one line saying so, and a custom screen should do the same.
let voter = try await VoteFirst.me()
if voter.kind == .anonymous {
showSignInHint = true
}
if voter.banned {
commentsEnabled = false
}What you see
Open Voters in the dashboard. A signed in vote sits against the person, with the name and email your token carried.
The owner sees a name where there was a handle.
Anonymous voters show a generated handle that says nothing about who they are.
An anonymous voter is given a stable handle such as VelvetOwl_3069. It is the same every time for that voter, which keeps a thread readable, and a signed in voter is called whatever the token said.
Name and email are written onto the voter from every token that arrives. Correct somebody's name in your own product and it is corrected here on their next visit, while earlier comments keep the name they were left under.
A voter belongs to one project. Your own id gives one customer a different voter on each of your projects, and no project can read another. Email is what links a vote to a customer's tier if you use revenue weighted voting, so send it when you have it.
Hand over a phone
forget() drops the anonymous token, the cached identity and anything queued to send. The next write mints a new voter with no history.
When the phone changes hands, forget the device.
It is a local reset, not a deletion request, and votes already cast stay on the board.
Call it when somebody signs out of your app entirely and gives the phone to somebody else. Pair it with signOut so the next person does not inherit the first person's anonymous history.
It does not clear what the reader chose to hide, because choosing not to see abuse again is not part of an identity.
func leaveAccount() async {
await VoteFirst.signOut()
await VoteFirst.forget()
}What signed in voters give you
Votes that follow the person
A new phone or a second device is still the same voter.
A name beside every request
You see which customer asked, not a generated handle.
Guests still welcome
Anyone without an account votes anonymously, with no setup.
Connect your accounts in four steps
The Swift side is a few lines.
Make the secret
Press Generate under SSO secret in Share & Embed and keep it on your server.
Sign on your server
Return a token with sub and exp, plus name and email if you have them.
Call signIn
Run VoteFirst.signIn(ssoToken:) after login and on every launch.
Check the dashboard
Vote while signed in and find the person under Voters.
What to know before you build it
- The sign in is held in memory, so call it again on every launch.
- Votes cast as a guest do not move to the person after signing in.
- A token cannot be withdrawn before it expires, so keep the expiry short.
- If the owner's plan lapses, the server stops accepting tokens and signIn throws identityInvalid.
iOS signed in vote questions
Must users be signed in?
No. Without it each device gets an anonymous voter, which is the right answer for an app with no accounts.
What happens to votes made before signing in?
They stay on the anonymous voter that cast them. Nothing already recorded moves to the signed in person.
Where does the secret go?
On your server only. Anyone holding it can claim to be any of your users, so it never ships in the app.
What if the token is refused?
signIn throws identityInvalid and the anonymous voter the device already had is still there.
Does signIn run on every launch?
Yes. The sign in is held in memory and not stored, so call it where you restore your own session.
Is the app voter the same as the website voter?
Not unless the person signs in on both. Signing in with the same token on each makes them one voter.
Which plan is needed?
The project owner must be on a plan with single sign on. Free holds the whole of Pro for one project and 100 votes, so you can try it first.
What does it cost?
Free needs no card. Beyond it, Lite is $9/mo and Pro is $39/mo, each with a 14 day trial and no card to start.
More on running your board
More on identity and the Swift package.
Single sign on for a board
The token, in Node, Python and Go.
A SwiftUI feedback form
Start the package and show a board.
A screen that works offline
Votes made with no signal are sent later.
What churned customers asked for
See which requests the people who cancelled had voted for.
Tell your users about an outage
A banner inside your SwiftUI app that ends by itself.
Swift voters
Where a voter comes from and how to make it a person you know.
Let your accounts do the voting
Try it on the Free plan, which asks for no card. When you outgrow it, Lite is $9/mo and Pro is $39/mo, and both start with a 14 day trial.