Database Adapters
gau
can work with any database, though currently no databases are supported directly.
It’s adviced to use an ORM, which abstracts the database away. gau
currently supports Drizzle with SQLite and PostgreSQL drivers.
The createAuth
function not only sets up your authentication logic but also returns a set of database methods from your adapter, allowing you to interact with your user data directly.
Database Methods
Section titled “Database Methods”Here are the methods returned by createAuth
, which you can use in your application’s server-side logic:
getUser
Section titled “getUser”Type:
(id: string) => Promise<User | null>
Retrieves a user by their unique ID.
getUserByEmail
Section titled “getUserByEmail”Type:
(email: string) => Promise<User | null>
Finds a user by their email address.
getUserByAccount
Section titled “getUserByAccount”Type:
(provider: string, providerAccountId: string) => Promise<User | null>
Fetches a user based on their linked OAuth account.
getAccounts
Section titled “getAccounts”Type:
(userId: string) => Promise<Account[]>
Retrieves all accounts linked to a user.
getUserAndAccounts
Section titled “getUserAndAccounts”Type:
(userId: string) => Promise<{ user: User, accounts: Account[] } | null>
Retrieves a user and all their linked accounts in a single call.
createUser
Section titled “createUser”Type:
(data: NewUser) => Promise<User>
Creates a new user in the database.
linkAccount
Section titled “linkAccount”Type:
(data: NewAccount) => Promise<void>
Links an OAuth account to an existing user.
unlinkAccount
Section titled “unlinkAccount”Type:
(provider: string, providerAccountId: string) => Promise<void>
Unlinks an OAuth account from a user.
updateUser
Section titled “updateUser”Type:
(data: Partial<User> & { id: string }) => Promise<User>
Updates a user’s information.
deleteUser
Section titled “deleteUser”Type:
(id: string) => Promise<void>
Deletes a user from the database.