Skip to content

Commit

Permalink
Remove all auth tokens of user along with deleting all sessions
Browse files Browse the repository at this point in the history
Also remove `Delete this session` button from each session and,
fix issue with auth token access of active login session, even after deleting sessions from admin.
  • Loading branch information
vicpatel committed Mar 1, 2022
1 parent 465e8ff commit 5ccf284
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 0 additions & 10 deletions auth/assets/templates/sessions.html.tpl
Expand Up @@ -31,16 +31,6 @@
{{ if .Current }}
<h5>{{ tr "sessions.template.list.current" }}</h5>
{{ end }}
{{ if not .Current }}
<button
type="submit"
name="delete"
value="{{ .ID }}"
class="btn btn-sm btn-link text-danger float-right"
>
{{ tr "sessions.template.list.delete" }}
</button>
{{ end }}
<label class="mb-0 d-block">{{ tr "sessions.template.list.authorized-on" }}</label>
<p class="w-75 d-inline-block">
<time datetime="{{ .CreatedAt }}">{{ .CreatedAt | date "Mon, 02 Jan 2006 15:04 MST" }}</time>
Expand Down
10 changes: 8 additions & 2 deletions auth/handlers/handle_sessions.go
Expand Up @@ -58,6 +58,7 @@ func (h *AuthHandlers) sessionsView(req *request.AuthReq) error {
}

func (h *AuthHandlers) sessionsProc(req *request.AuthReq) error {
ctx := req.Context()
ss, err := h.getSessions(req)
if err != nil {
return err
Expand All @@ -70,11 +71,16 @@ func (h *AuthHandlers) sessionsProc(req *request.AuthReq) error {
continue
}

if err = h.SessionManager.DeleteByID(req.Context(), s.id); err != nil {
if err = h.SessionManager.DeleteByID(ctx, s.id); err != nil {
return err
}
}

err = h.TokenService.DeleteByUserID(ctx, req.AuthUser.User.ID)
if err != nil {
return err
}

t := translator(req, "auth")
req.NewAlerts = append(req.NewAlerts, request.Alert{
Type: "primary",
Expand All @@ -86,7 +92,7 @@ func (h *AuthHandlers) sessionsProc(req *request.AuthReq) error {
continue
}

if err = h.SessionManager.DeleteByID(req.Context(), s.id); err != nil {
if err = h.SessionManager.DeleteByID(ctx, s.id); err != nil {
return err
}
}
Expand Down

0 comments on commit 5ccf284

Please sign in to comment.