How to add user login to your app.
Email, Google, and Apple.
By Timothy Lindblom, Founder, Newly
Learning how to add user login to your app usually means working through JWTs, refresh tokens, password resets, social OAuth, and secure storage. With Newly you describe it in a sentence: “add login with email and Google.” You get email and password, Google, and native Apple Sign In running on Better Auth and Newly Backend, with the React Native code in your project.
The five steps
How to add user login to your app, start to finish.
One prompt from you, four moves from Newly. You describe the login you want; the client, the hook, the backend, the secure storage, and the gate around your protected screens follow. Here is the sequence in order.
- 1
Prompt the AI for the login you want
There's no config screen to open. You type a sentence. Something like “add login with email and Google” is enough for Newly to scaffold auth into your project. That is what learning how to add user login to your app comes down to here: you describe the behavior and the AI assembles the libraries. Want Apple next to Google? Say so. Only email and password for now? Say that instead.
- 2
Newly generates the auth client and useAuth() hook
Behind that sentence, Newly writes the auth client – Better Auth with its Expo plugin – and an auth context that exposes a useAuth() hook. A component calls useAuth() to find out whether someone is signed in, who they are, and how to sign them out. The same pass generates API helpers that attach the user's token to outgoing requests, so your data calls go out authorized without you threading a token through every fetch.
- 3
The backend tables and /api/auth/* endpoints appear
Auth needs somewhere to live. On Newly Backend, Newly creates the four tables Better Auth expects – users, sessions, accounts, verification – and the /api/auth/* endpoints in front of them. users is your people. sessions is who is logged in right now. accounts ties one person to each method they sign in with (email, Google, Apple). verification backs flows like email confirmation. It's ordinary Postgres you can query, not a schema you had to design.
- 4
Sessions persist in expo-secure-store on the device
Once a user signs in, the session sticks. Newly stores the JWT in expo-secure-store – the iOS Keychain, the encrypted Android Keystore – and the token rides along on each request for the server to check against the sessions table. Users stay logged in across restarts until they sign out. The reason that matters is below in the storage breakdown: the credential sits in OS-level secure storage, not the readable kind.
- 5
Wrap protected screens in the auth provider
The agent adds the sign-in state your screens need and redirects signed-out users to login. Your API also needs server-side checks for each protected action and each user’s data. Add Google and Apple credentials before testing social login. Test with two separate accounts to check that the access rules match your app.
What the prompt generates for you.
Much of how to add user login to your app feels hard because most of the work never shows up on screen. You write a prompt and that part gets written for you: the client, the hook, the tables, the secure storage, and the gate. You read the result, adjust what you want, and carry on building.
User logins, at a glance.
The auth library Newly wires in, with its tables and helpers generated
“Add login with email and Google” – Newly generates the rest
Email/password, Google, and native Apple Sign In on iOS
Persisted in expo-secure-store, generated and wired for you
What it is
Login is a system, not a screen.
The login screen is the part you see. Most of the work is the part you don’t. When people ask how to add user login to your app, what they actually need is a chain: a way to issue and refresh tokens, somewhere safe to store them on the device, a backend table that remembers who is signed in, and a gate in front of the screens that require an account. Break one link and you’ve got a form that looks like login but forgets everyone the moment they close the app.
Newly builds that chain for you. You write the prompt; the AI writes the client, the session storage, the tables, and the gate, and wires them together. The rest of this guide walks the chain link by link, so you can see what each piece does and adjust it when you need to.
The pieces
Five parts of login, all generated.
Ask how to add user login to your app and this is the parts list. Five files, each with one job. They land in your project as plain React Native and Postgres, so you can read any of them and edit them when you need to.
The auth client (Better Auth + Expo plugin)
The library layer that talks to your auth endpoints. Newly builds it on Better Auth and its Expo plugin, so the React Native side knows how to sign in, sign out, and read the current session. It arrives already pointed at your project's backend, so there's no library to choose or plugin to configure first.
The auth context and useAuth() hook
Where the login state lives. The generated auth context tracks who is signed in and exposes a useAuth() hook. Any screen calls useAuth() to read the current user or trigger sign-out, so “show this only to logged-in users” becomes a one-line check rather than a session object prop-drilled down the tree.
Authenticated API helpers
These keep your data calls authorized. Newly generates helpers that attach the user's JWT to every request as a bearer token, so the backend always knows who is asking. You write the fetch for your feature and the token plumbing is already taken care of.
Backend tables and /api/auth/* endpoints
On Newly Backend, Newly creates the users, sessions, accounts, and verification tables and the /api/auth/* endpoints in front of them. This is the server side of login, sitting in your project's own database as tables you can query directly.
Secure session storage
Sessions persist as JWT bearer tokens in expo-secure-store – the iOS Keychain, the Android Keystore – so they survive restarts and stay out of readable storage. The generated code writes the token on login and the server checks it against the sessions table on every authenticated request after that.
Login methods
Email, Google, and Apple.
Ask the agent for accounts and it adds email and password sign-in with Newly Backend. Password-reset and email-verification messages come built in. Newly sends them from no-reply@ your app’s domain once that domain is verified for email, so there is no email provider or API key to set up.
Ask for Google or Apple sign-in and the agent adds the buttons and connects them to your app’s sign-in service. Create credentials in your own Google or Apple developer account, then add them to the Sign-in service in Backend secrets.
Follow the sign-in setup guide for provider credentials, email sending and testing. Set production secrets before deploying your released app.
Your login setup
What the agent builds. What you add.
Describe the account flow your users need. The agent builds the screens and server connection, and Newly hosts the sign-in service. You add the credentials for Google and Apple sign-in, and Newly sends your sign-in emails from your own domain.
Newly Backend (bundled default)
Better Auth, configured for you.
- Better Auth added when your app needs accounts
- Google and Apple buttons connected to your credentials
- users, sessions, accounts, verification generated
- Included, with no extra dashboard or API keys to copy
- JWT in expo-secure-store, validated server-side
Your provider accounts
Credentials for your app’s sign-in methods.
- Your Google and Apple sign-in credentials
- A domain verified for email, so Newly sends reset emails from it
- Backend secrets set for dev and production
- Google and Apple use credentials from your developer accounts
- Test your app’s access checks with separate user accounts
Add your provider credentials in Settings → Project → Backend secrets → Sign-in. The sign-in docs cover the setup for dev and production.
Generated vs by hand
What Newly generates vs what you’d write.
Rolling your own auth is about a month of focused work, and it lands on the one layer where a small mistake becomes a breach. The left column is what Newly writes for you. The right is the identical list, done by hand. The difference is mostly the time it takes.
Newly generates it
- Better Auth client with the Expo plugin, wired in
- Auth context and a useAuth() hook your screens read
- Authenticated API helpers that attach the bearer token
- users, sessions, accounts, verification tables generated
- /api/auth/* endpoints on Newly Backend
- JWT stored in expo-secure-store, validated server-side
- Google and Apple sign-in wired to your own credentials
- Native Apple Sign In via expo-apple-authentication on iOS
You write it by hand
- JWT issuing plus refresh-token rotation logic
- Secure token storage on both iOS and Android
- Password reset and email verification flows
- Google and Apple OAuth: redirect URIs, native sheet
- A sessions table and protected-route checks
- Edge cases: expired tokens, revoked sessions, linking
- OAuth credentials from your developer accounts
- Access checks for each user’s data
What it costs and what you get.
From $25 a month, Newly generates the full login stack on Better Auth and Newly Backend and adds the React Native and Expo code to your project, where you can read and change it. Login isn’t metered per user.
FAQ
How to add user login to your app, answered straight.
Describe the login you want, such as “let people create an account with email and password.” The agent adds Newly Backend if needed, builds the sign-up and sign-in screens and connects them to the sign-in service. Newly hosts the backend. For Google or Apple sign-in, add credentials from your own developer account using the steps in the sign-in docs.
Add login with a single prompt.
That is how to add user login to your app without losing a month to it. From $25 a month, Newly generates email, Google, and Apple sign-in on Better Auth and Newly Backend, and the React Native code lives in your project.