uniqueUserId property
String
get
uniqueUserId
Gets a persistent, anonymous id for the current user. This method is copied from serverpod CLI.
Implementation
static String get uniqueUserId {
const uuidFilePath = 'uuid';
try {
final userIdFile =
File(p.join(_localStorageDirectory.path, uuidFilePath));
final userId = userIdFile.readAsStringSync();
return userId;
} catch (e) {
// Failed to read userId from file, it's probably not created.
}
final userId = const Uuid().v4();
try {
final userIdFile =
File(p.join(_localStorageDirectory.path, uuidFilePath));
userIdFile.createSync(recursive: true);
userIdFile.writeAsStringSync(userId);
} finally {}
return userId;
}