fix: update user on login

This commit is contained in:
Jozef Steinhübl 2024-08-19 23:41:28 +02:00
parent ee07e4e72d
commit 0cdb41abb7
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F
2 changed files with 16 additions and 0 deletions

View file

@ -50,6 +50,20 @@ export async function GET(context: APIContext): Promise<Response> {
sessionCookie.value, sessionCookie.value,
sessionCookie.attributes sessionCookie.attributes
); );
await context.locals.runtime.env.DB.prepare(
"UPDATE user SET username = ?2, avatar = ?3, access_token = ?4,access_token_expiration = ?5, refresh_token = ?6 WHERE discord_id = ?1"
)
.bind(
discordUser.id,
discordUser.username,
discordUser.avatar,
tokens.accessToken,
tokens.accessTokenExpiresAt.getTime(),
tokens.refreshToken
)
.first<UserRow>();
return context.redirect("/dashboard"); return context.redirect("/dashboard");
} }

View file

@ -8,6 +8,8 @@ export async function GET(context: APIContext): Promise<Response> {
scopes: ["identify", "guilds"], scopes: ["identify", "guilds"],
}); });
console.log("login");
context.cookies.set("discord_oauth_state", state, { context.cookies.set("discord_oauth_state", state, {
path: "/", path: "/",
secure: import.meta.env.PROD, secure: import.meta.env.PROD,