简体   繁体   中英

Storing authenticated user data with Realm or UserDefaults?

My app is similar to Twitter where people can make posts and you can follow others to see their posts in your feed. When the user signs in to their account, and the API sends back the user data, I need to store that authenticated user's data.

I already have a Realm User class set up, but I use this class to store user data from other users' posts. So my question is, how should I store the authenticated user's data? There are two options I've thought of, but both seem wrong:

  1. Create an AuthenticatedUser realm class and store it there. I don't think realm supports subclassing other realm classes (in this case my already existing User class), so this doesn't seem like the right solution.
  2. Store the user's data in UserDefaults , but again, this doesn't seem right if I'm already using realm.

What should I do here? What's the best approach to solving this?

IMO, you should use Realm to store the user data but not in plain format. Use Encryption supported by Realm. They support AES-256 encryption for stored data. Please see this url: " https://realm.io/products/realm-database/ ". sub classes needs to be handled separately by storing each and every classes and relationship has to be maintained by us.

User defaults is a big no for storing sensitive information. It is stored in plist in binary format, with no encryption, and is stored in your app's directory. Please find the details below: " https://www.andyibanez.com/nsuserdefaults-not-for-sensitive-data/ "

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM