tangled
alpha
login
or
join now
tjh.dev
/
test
forked from
tangled.org/core
0
fork
atom
Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork
atom
overview
issues
pulls
pipelines
fix redirect in follow/star buttons
oppi.li
1 year ago
474bbfbc
a97cea48
+15
-5
1 changed file
expand all
collapse all
unified
split
appview
state
middleware.go
+15
-5
appview/state/middleware.go
···
21
21
func AuthMiddleware(s *State) Middleware {
22
22
return func(next http.Handler) http.Handler {
23
23
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
24
24
+
redirectFunc := func(w http.ResponseWriter, r *http.Request) {
25
25
+
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
26
26
+
}
27
27
+
if r.Header.Get("HX-Request") == "true" {
28
28
+
redirectFunc = func(w http.ResponseWriter, _ *http.Request) {
29
29
+
w.Header().Set("HX-Redirect", "/login")
30
30
+
w.WriteHeader(http.StatusOK)
31
31
+
}
32
32
+
}
33
33
+
24
34
session, err := s.auth.GetSession(r)
25
35
if session.IsNew || err != nil {
26
36
log.Printf("not logged in, redirecting")
27
27
-
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
37
37
+
redirectFunc(w, r)
28
38
return
29
39
}
30
40
31
41
authorized, ok := session.Values[appview.SessionAuthenticated].(bool)
32
42
if !ok || !authorized {
33
43
log.Printf("not logged in, redirecting")
34
34
-
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
44
44
+
redirectFunc(w, r)
35
45
return
36
46
}
37
47
···
51
41
expiry, err := time.Parse(time.RFC3339, expiryStr)
52
42
if err != nil {
53
43
log.Println("invalid expiry time", err)
54
54
-
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
44
44
+
redirectFunc(w, r)
55
45
return
56
46
}
57
47
pdsUrl, ok1 := session.Values[appview.SessionPds].(string)
···
60
50
61
51
if !ok1 || !ok2 || !ok3 {
62
52
log.Println("invalid expiry time", err)
63
63
-
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
53
53
+
redirectFunc(w, r)
64
54
return
65
55
}
66
56
···
78
68
atSession, err := comatproto.ServerRefreshSession(r.Context(), &client)
79
69
if err != nil {
80
70
log.Println("failed to refresh session", err)
81
81
-
http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
71
71
+
redirectFunc(w, r)
82
72
return
83
73
}
84
74