This commit is contained in:
Andre Henriques 2024-05-02 16:58:01 +01:00
parent 29b69deaf6
commit 7d346ba2ce
3 changed files with 18 additions and 1 deletions

View File

@ -412,6 +412,18 @@ func UsersEndpints(db db.Db, handle *Handle) {
return c.SendJSON("Ok") return c.SendJSON("Ok")
}) })
handle.DeleteAuth("/user/token/logoff", User_Normal, func(c *Context) *Error {
if c.Token == nil {
return c.JsonBadRequest("Failed to get token")
}
_, err := c.Db.Exec("delete from tokens where token=$1;", c.Token)
if err != nil {
return c.E500M("Failed to delete token", err)
}
return c.SendJSON("OK")
})
type DeleteUser struct { type DeleteUser struct {
Id string `json:"id" validate:"required"` Id string `json:"id" validate:"required"`
Password string `json:"password" validate:"required"` Password string `json:"password" validate:"required"`

View File

@ -175,7 +175,7 @@ func (x *Handle) DeleteAuth(path string, authLevel dbtypes.UserType, fn func(c *
} }
return fn(c) return fn(c)
} }
x.posts = append(x.posts, HandleFunc{path, inner_fn}) x.deletes = append(x.deletes, HandleFunc{path, inner_fn})
} }
func DeleteAuthJson[T interface{}](x *Handle, path string, authLevel dbtypes.UserType, fn func(c *Context, obj *T) *Error) { func DeleteAuthJson[T interface{}](x *Handle, path string, authLevel dbtypes.UserType, fn func(c *Context, obj *T) *Error) {

View File

@ -1,4 +1,5 @@
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { rdelete } from '$lib/requests.svelte';
type User = { type User = {
token: string; token: string;
@ -33,6 +34,10 @@ export function createUserStore() {
if (value) { if (value) {
localStorage.setItem('user', JSON.stringify(value)); localStorage.setItem('user', JSON.stringify(value));
} else { } else {
if (user) {
// Request the deletion of the token
rdelete('/user/token/logoff', {});
}
localStorage.removeItem('user'); localStorage.removeItem('user');
} }
user = value; user = value;