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.
Extending the Schema
Section titled “Extending the Schema”You can add custom fields to gau-managed tables using a d.ts file.
1. Update Schema
Section titled “1. Update Schema”Add your custom columns to the Drizzle schema.
import { text } from 'drizzle-orm/sqlite-core'
export const Users = sqliteTable('users', { // ... nickname: text(),})2. Augment Types
Section titled “2. Augment Types”Create a declaration file to override the default User interface. This ensures auth.session.user.nickname is typed correctly.
import '@rttnd/gau'
declare module '@rttnd/gau' { interface User { nickname?: string | null }}