(ns auto-ap.ssr.auth
  (:require [auto-ap.session-version :as session-version]
            [buddy.sign.jwt :as jwt]
            [config.core :refer [env]]))

(defn logout [request]
  {:status 301
   :headers {"Location" "/login"}
   :session {}})


(defn impersonate [request]
  {:status  200
   :session {:identity (dissoc (jwt/unsign (get-in request [:query-params "jwt"])
                                           (:jwt-secret env)
                                           {:alg :hs512})
                               :exp)
             :version session-version/current-session-version}})
