fix: keep unauthenticated user logged in if allowed #114
This commit is contained in:
parent
f0d0e43929
commit
bc4ad49285
1 changed files with 12 additions and 10 deletions
|
|
@ -415,21 +415,23 @@ const app = new Elysia({
|
||||||
user = await jwt.verify(auth.value);
|
user = await jwt.verify(auth.value);
|
||||||
|
|
||||||
if (user !== false && user.id) {
|
if (user !== false && user.id) {
|
||||||
// make sure user exists in db
|
if (Number.parseInt(user.id) < 2 ** 24 || !ALLOW_UNAUTHENTICATED) {
|
||||||
const existingUser = db
|
// make sure user exists in db
|
||||||
.query("SELECT * FROM users WHERE id = ?")
|
const existingUser = db
|
||||||
.as(User)
|
.query("SELECT * FROM users WHERE id = ?")
|
||||||
.get(user.id);
|
.as(User)
|
||||||
|
.get(user.id);
|
||||||
|
|
||||||
if (!existingUser) {
|
if (!existingUser) {
|
||||||
if (auth?.value) {
|
if (auth?.value) {
|
||||||
auth.remove();
|
auth.remove();
|
||||||
|
}
|
||||||
|
return redirect("/login", 302);
|
||||||
}
|
}
|
||||||
return redirect("/login", 302);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ALLOW_UNAUTHENTICATED) {
|
} else if (ALLOW_UNAUTHENTICATED) {
|
||||||
const newUserId = String(randomInt(2 ^ 24, Number.MAX_SAFE_INTEGER));
|
const newUserId = String(randomInt(2 ** 24, Number.MAX_SAFE_INTEGER));
|
||||||
const accessToken = await jwt.sign({
|
const accessToken = await jwt.sign({
|
||||||
id: newUserId,
|
id: newUserId,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue