Download this file
| 1 | package sheets |
| 2 | |
| 3 | import "net/http" |
| 4 | |
| 5 | // requireSession is auth.RequireSession in production and a |
| 6 | // pass-through when there is no auth to require one with. |
| 7 | // |
| 8 | // The pass-through is for tests only, and it is deliberate rather than |
| 9 | // accidental: a nil-auth App has no sessions at all, so requiring one |
| 10 | // would make every route below untestable without a mailer, an SMTP |
| 11 | // refusal and a full magic-link round trip. Production cannot reach it |
| 12 | // — main exits before New if sign-in is not configured. |
| 13 | func (a *App) requireSession(next http.Handler) http.Handler { |
| 14 | if a.home != nil { |
| 15 | return a.signedInRequire(next) |
| 16 | } |
| 17 | if a.auth == nil { |
| 18 | return next |
| 19 | } |
| 20 | return a.auth.RequireSession(a.rejectDisabledHome(next)) |
| 21 | } |
| 22 | |
| 23 | // signedInRequire is the Home-mode guard: the roster's in team mode, |
| 24 | // the allowlist's otherwise. |
| 25 | func (a *App) signedInRequire(next http.Handler) http.Handler { |
| 26 | if a.team != nil { |
| 27 | return a.teamRequire(next) |
| 28 | } |
| 29 | return a.homeRequire(next) |
| 30 | } |
| 31 | |