logoutHandler logs out the user and unsets the token stored
()
| 896 | |
| 897 | // logoutHandler logs out the user and unsets the token stored |
| 898 | func (s *Server) logoutHandler() http.Handler { |
| 899 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 900 | // Logout the CLI |
| 901 | err := auth.Logout(r.Context(), s.app.ch) |
| 902 | if err != nil { |
| 903 | http.Error(w, fmt.Sprintf("failed to logout: %s", err), http.StatusInternalServerError) |
| 904 | return |
| 905 | } |
| 906 | |
| 907 | // Get URL for cloud auth. |
| 908 | authURL := s.app.ch.AdminURL() |
| 909 | |
| 910 | // Logout on cloud as well |
| 911 | var qry map[string]string |
| 912 | if r.URL.Query().Get("redirect") != "" { |
| 913 | qry = map[string]string{"redirect": r.URL.Query().Get("redirect")} |
| 914 | } |
| 915 | logoutURL, err := urlutil.WithQuery(urlutil.MustJoinURL(authURL, "auth", "logout"), qry) |
| 916 | if err != nil { |
| 917 | http.Error(w, fmt.Sprintf("failed to create logout URL: %s", err), http.StatusInternalServerError) |
| 918 | return |
| 919 | } |
| 920 | |
| 921 | http.Redirect(w, r, logoutURL, http.StatusFound) |
| 922 | }) |
| 923 | } |
| 924 | |
| 925 | // trackingHandler proxies events to intake.rilldata.io. |
| 926 | func (s *Server) trackingHandler() http.Handler { |
no test coverage detected