Implements authentication, login flows, session/request guards, policies, and permission checks in Laravel for Go. Use when working on login, registration, logout, protected routes, policies, email verification, password resets, or social login.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Auth And Authorization?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/airshell-auth-and-authorization-laravel-php-to-rust-go)
---
name: auth-and-authorization
description: Implements authentication, login flows, session/request guards, policies, and permission checks in Laravel for Go. Use when working on login, registration, logout, protected routes, policies, email verification, password resets, or social login.
---
# Authentication & Authorization
Consult the installed framework docs (locate via `.agents/skills/writing-laravel-go-apps/scripts/docs-path.sh`) for complete details: `authentication.md`, `authorization.md`, `passwords.md`, `verification.md`, and `social-login.md`.
## Authentication
- Your user model in `models/user.go` provides `ID`, `Password`, and `RememberToken`. Always keep `json:"-"` on `Password` and `RememberToken` (and any other secret fields) so they never leak into Inertia props or JSON responses.
- `auth.Session[models.User]{}` is appended to `m.Web` in `bootstrap/app.go`. Register one session middleware for one `User` type, and represent roles (like admin) on `User` and check them in policies rather than adding extra guards.
- Retrieve the signed-in user with `models.CurrentUser(r)` (which returns `nil` for guests). Protect route groups with auth middleware—don't hand-roll session checks inside handlers.
- Name core auth routes (such as `.Name("login")`) so guest redirects, password resets, and email verification links resolve to the right URLs.
- Apply rate limiting to login, password reset, and verification endpoints.
## Authorization & Policies
- Authentication is not authorization, and validation is not authorization—always check permissions explicitly on protected actions. Prefer `404` over `403` when cross-tenant isolation should not reveal whether a record exists.
- Define policies as functions returning `auth.Ability[models.User]` right below the model in `models/<model>.go` (or in `policies/<model>.go` if the project already uses a `policies/` package).
- Return `auth.Allow(condition)` for boolean checks or `auth.Deny("...")` when you need a custom denial message.
- Check abilities in handlers with `if err := auth.Authorize(r, ...); err != nil { return web.Fail(err) }`, or authorize directly on a form struct via its `Authorize` method.
```go
// models/post.go (below the Post struct)
func UpdatePost(post *Post) auth.Ability[User] {
return func(user *User) error {
return auth.Allow(user.ID == post.UserID)
}
}
func DeletePost(post *Post) auth.Ability[User] {
return func(user *User) error {
return auth.Allow(user.ID == post.UserID)
}
}
```