Skip to content

Working with the authenticated user

Greg Bowler edited this page Jun 23, 2020 · 1 revision

After authentication, AuthUser gives the application a small immutable identity snapshot.

Protecting a page

if !auth.IsLoggedIn() {
    if err := auth.Login(nil); err != nil { return nil, err }
}
user, err := auth.GetAuthUser()
if err != nil { return nil, err }

Return the login error immediately so the adapter can redirect. Reading an absent user returns ErrNotLoggedIn.

Identifying a user

userID := user.ID()
email := user.Email()

Associate local records with the provider ID. Treat it as a string. Email addresses can change. The client exposes only ID and email; changes to application records do not update the provider.

Keeping permissions in the application

Authentication identifies the visitor. Check their permissions before showing private records or allowing changes. For example, load an order using both its order ID and authenticated user ID. Escape identity values when rendering HTML.


Next, see Responding to a new authentication.

Clone this wiki locally