auth

package
v0.0.0-...-4d14c86 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package auth lets through the requests of a logged-in account only, and tells the routes which one.

Index

Constants

View Source
const Cookie = "notes_session"

Cookie holds the session token of the web app: HttpOnly, page scripts never see it.

Variables

This section is empty.

Functions

func New

func New(db bun.IDB, next http.Handler) http.Handler

New runs next with the account of the request's session in its context: the cookie, or a "Authorization: Bearer <token>" header for scripts, a session token or an API token. Without a valid one, 401.

func SetCookie

func SetCookie(w http.ResponseWriter, token string, expires time.Time)

SetCookie gives the browser the session token until expires; a zero time deletes it. Secure works on http://localhost too: browsers count it as a secure context.

func Token

func Token(r *http.Request) string

Token is the request's session token, "" without one.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址