pub enum IdStrategy {
Ulid,
UuidV7,
UuidV4,
Custom(Arc<dyn Fn() -> String + Send + Sync>),
}Expand description
How fastauth generates the ids of the rows it creates: users, sessions, accounts,
verifications and every row a plugin creates through ctx.new_id().
Set it with FastAuth::builder().ids(..). The strategy also picks how id columns are
stored (IdStrategy::storage): the UUID strategies use Postgres’ native uuid type,
the others text. Switching strategies on an existing database doesn’t convert its
columns; the migrator warns about the mismatch instead.
use fastauth_core::config::IdStrategy;
let id = IdStrategy::default().generate().unwrap();
assert_eq!(id.as_str().len(), 26);
let custom = IdStrategy::custom(|| {
format!("usr_{}", fastauth_core::crypto::random_string(12, b"0123456789abcdef"))
});
assert!(custom.generate().unwrap().as_str().starts_with("usr_"));Variants§
Ulid
A ULID: 26 characters of Crockford base32, sortable
by creation time. Stored as text. The default.
UuidV7
A UUIDv7 in hyphenated form, sortable by creation time. Stored as uuid on Postgres.
UuidV4
A random UUIDv4 in hyphenated form. Stored as uuid on Postgres.
Custom(Arc<dyn Fn() -> String + Send + Sync>)
Ids from your own function, stored as text. Every id is checked when it’s
generated: an empty one, or one longer than IdStrategy::MAX_LEN bytes, fails the
request with a 500 and an error log line. Ids must be unique; fastauth doesn’t retry.