Add JoinPage feature with invite token handling and update routing
This commit is contained in:
@@ -110,6 +110,11 @@ func NewRouter(cfg *config.Config, db *database.DB, jwtManager *jwt.Manager, aut
|
||||
// Health check
|
||||
r.Get("/health", healthHandler)
|
||||
|
||||
// Join org by invite token (public)
|
||||
r.Get("/join", func(w http.ResponseWriter, req *http.Request) {
|
||||
getOrgByInviteTokenHandler(w, req, db)
|
||||
})
|
||||
|
||||
// WOPI routes (public, token validation done per endpoint)
|
||||
r.Route("/wopi", func(r chi.Router) {
|
||||
r.Route("/files/{fileId}", func(r chi.Router) {
|
||||
@@ -317,6 +322,29 @@ func NewRouter(cfg *config.Config, db *database.DB, jwtManager *jwt.Manager, aut
|
||||
return r
|
||||
}
|
||||
|
||||
func getOrgByInviteTokenHandler(w http.ResponseWriter, r *http.Request, db *database.DB) {
|
||||
token := r.URL.Query().Get("token")
|
||||
if token == "" {
|
||||
errors.WriteError(w, errors.CodeInvalidArgument, "Token required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var org database.Organization
|
||||
err := db.QueryRowContext(r.Context(), `
|
||||
SELECT id, owner_id, name, slug, created_at
|
||||
FROM organizations
|
||||
WHERE invite_link_token = $1
|
||||
`, token).Scan(&org.ID, &org.OwnerID, &org.Name, &org.Slug, &org.CreatedAt)
|
||||
if err != nil {
|
||||
errors.LogError(r, err, "Invalid invite token")
|
||||
errors.WriteError(w, errors.CodeNotFound, "Invalid token", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(org)
|
||||
}
|
||||
|
||||
func healthHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("OK"))
|
||||
|
||||
Reference in New Issue
Block a user