Skip to content

Commit df060e5

Browse files
committed
fixed permission denied page and logout
1 parent 38be83f commit df060e5

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

pkg/auth/service.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func (s *Service) callback(w http.ResponseWriter, r *http.Request) {
176176
Expires: newToken.ExpiresAt,
177177
Secure: true,
178178
Path: "/",
179+
HttpOnly: true,
179180
SameSite: http.SameSiteStrictMode,
180181
}
181182

@@ -344,18 +345,21 @@ func (s *Service) listProviders(w http.ResponseWriter, _ *http.Request) {
344345

345346
// Logout
346347
func (s *Service) logout(w http.ResponseWriter, r *http.Request) {
348+
token := s.TokenProvider.FromRequest(r)
349+
350+
if token != nil && s.TokenProvider.Delete(token) != nil {
351+
w.WriteHeader(http.StatusInternalServerError)
352+
}
353+
347354
cookie := &http.Cookie{
348355
Name: cookieName,
356+
Secure: true,
357+
Path: "/",
358+
HttpOnly: true,
349359
SameSite: http.SameSiteStrictMode,
350360
}
351361

352362
http.SetCookie(w, cookie)
353363

354-
token := s.TokenProvider.FromRequest(r)
355-
356-
if token != nil && s.TokenProvider.Delete(token) != nil {
357-
w.WriteHeader(http.StatusInternalServerError)
358-
}
359-
360364
w.WriteHeader(http.StatusNoContent)
361365
}

web/speakerbob/src/components/UserMenu.vue

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<v-list-item-title>Preferences</v-list-item-title>
1111
</v-list-item>
1212
<v-spacer />
13-
<v-list-item @click="goto('logout')">
13+
<v-list-item @click="logout">
1414
<v-list-item-title>Logout</v-list-item-title>
1515
</v-list-item>
1616
</v-list>
@@ -20,25 +20,35 @@
2020
<script lang="ts">
2121
import { Vue, Component } from 'vue-property-decorator'
2222
import { UserPreferences } from '@/definitions/userpreferences'
23+
import axios from 'axios'
2324
2425
@Component
2526
export default class UserMenu extends Vue {
2627
public disabled = false
2728
public user: UserPreferences = new UserPreferences();
2829
2930
public async created () {
30-
const resp = await this.$auth.get('/user/preferences/')
31-
32-
if (resp.status === 404) {
33-
this.disabled = true
34-
return
31+
try {
32+
const resp = await axios.get('/auth/user/preferences/')
33+
this.user = resp.data
34+
} catch (e) {
35+
if (axios.isAxiosError(e)) {
36+
if (!!e.response && (e.response.status === 404 || e.response.status === 401)) {
37+
this.disabled = true
38+
return
39+
}
40+
}
41+
throw e
3542
}
36-
37-
this.user = resp.data
3843
}
3944
4045
private async goto (path: string) {
4146
await this.$router.push(path)
4247
}
48+
49+
private logout () {
50+
this.disabled = true
51+
this.goto('logout')
52+
}
4353
}
4454
</script>

0 commit comments

Comments
 (0)