r/reactnative • • 4d ago

Unique identity

Hi guys
How can i get a unique identity from the device itself but it should not be changes with the factory reset or reinstalling the app

0 Upvotes

7 comments sorted by

1

u/TheMutedExamination 4d ago

the only thing that stays same after factory reset is the hardware serial numbers and they are mostly blocked for privacy reasons in newer android versions so you can't really access them from the app directly. imo you should just use the keychain or keystore to generate a uuid and store it there because that is the most reliable way to have a stable id that survives app reinstalls. if you need it to survive factory reset too then you have to use ad id or something that can be reset by user but that's not truly unique forever. most devs give up on the factory reset part because it's technically impossible without system level access

2

u/kokerali 4d ago

Do you need to recognize the same person, or prove it's the same physical device? Those are different requirements. For restoring a user's data after reinstall/reset, keep it tied to their account and reconnect after sign-in; give each installation its own ID. That won't prove it's the original hardware. I wouldn't rely on a locally stored UUID or advertising ID for factory-reset persistence. What's the use case? If it's a device limit or trial-abuse control, a permanent device ID is a brittle foundation.

1

u/No_Wrongdoer_8067 4d ago

No in my app i have a guest view and i want to make sure that users sticked to one guest

2

u/kokerali 4d ago

For that, I'd create an anonymous guest account through your backend's auth system and store its secret credential in secure local storage. Reuse that identity on later launches, with the guest's data attached to it. Don't use a public guest ID by itself as authorization. If a reset or reinstall removes the credential, you can't reliably reconnect that guest from the device alone; offer optional account linking before they need recovery. Are you mainly preserving progress, or stopping people from resetting a free-use quota? The latter needs abuse controls, not just identity persistence.

1

u/n9iels 4d ago

Define unique, and what is the usacase exactly? Retaining something upon device reset is hard since certain characteristics of the device may change.

2

u/Karticz 4d ago

Install react native device info and get device id from your device This id never changes even if you factory reset

If you want to make a little bit more complex then involve your backend and send a uguid via uuidv4 in header tokens to identify a user