closes #101
This commit is contained in:
parent
29b69deaf6
commit
7d346ba2ce
@ -412,6 +412,18 @@ func UsersEndpints(db db.Db, handle *Handle) {
|
||||
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 {
|
||||
Id string `json:"id" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
|
@ -175,7 +175,7 @@ func (x *Handle) DeleteAuth(path string, authLevel dbtypes.UserType, fn func(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) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import { rdelete } from '$lib/requests.svelte';
|
||||
|
||||
type User = {
|
||||
token: string;
|
||||
@ -33,6 +34,10 @@ export function createUserStore() {
|
||||
if (value) {
|
||||
localStorage.setItem('user', JSON.stringify(value));
|
||||
} else {
|
||||
if (user) {
|
||||
// Request the deletion of the token
|
||||
rdelete('/user/token/logoff', {});
|
||||
}
|
||||
localStorage.removeItem('user');
|
||||
}
|
||||
user = value;
|
||||
|
Loading…
Reference in New Issue
Block a user