diff --git a/src/api/routes/users/@me/connections/#connection_name/#connection_id/access-token.ts b/src/api/routes/users/@me/connections/#connection_name/#connection_id/access-token.ts
index 760f8135..1ad1c7a7 100644
--- a/src/api/routes/users/@me/connections/#connection_name/#connection_id/access-token.ts
+++ b/src/api/routes/users/@me/connections/#connection_name/#connection_id/access-token.ts
@@ -19,7 +19,7 @@ const ALLOWED_CONNECTIONS = ["twitch", "youtube"];
router.get("/", route({}), async (req: Request, res: Response) => {
const { connection_name, connection_id } = req.params;
- const connection = ConnectionStore.connections.get(connection_id);
+ const connection = ConnectionStore.connections.get(connection_name);
if (!ALLOWED_CONNECTIONS.includes(connection_name) || !connection)
throw FieldErrors({
@@ -41,7 +41,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
const connectedAccount = await ConnectedAccount.findOne({
where: {
type: connection_name,
- id: connection_id,
+ external_id: connection_id,
user_id: req.user_id,
},
select: [
@@ -64,14 +64,12 @@ router.get("/", route({}), async (req: Request, res: Response) => {
throw new ApiError("No token data", 0, 400);
let access_token = connectedAccount.token_data.access_token;
- const { expires_at, expires_in } = connectedAccount.token_data;
+ const { expires_at, expires_in, fetched_at } = connectedAccount.token_data;
- if (expires_at && expires_at < Date.now()) {
- if (!(connection instanceof RefreshableConnection))
- throw new ApiError("Access token expired", 0, 400);
- const tokenData = await connection.refresh(connectedAccount);
- access_token = tokenData.access_token;
- } else if (expires_in && expires_in < Date.now()) {
+ if (
+ (expires_at && expires_at < Date.now()) ||
+ (expires_in && fetched_at + expires_in * 1000 < Date.now())
+ ) {
if (!(connection instanceof RefreshableConnection))
throw new ApiError("Access token expired", 0, 400);
const tokenData = await connection.refresh(connectedAccount);
diff --git a/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts b/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts
index 9d5f517d..07440eac 100644
--- a/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts
+++ b/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts
@@ -1,5 +1,10 @@
import { route } from "@fosscord/api";
-import { ConnectedAccount, DiscordApiErrors, emitEvent, ConnectionUpdateSchema } from "@fosscord/util";
+import {
+ ConnectedAccount,
+ ConnectionUpdateSchema,
+ DiscordApiErrors,
+ emitEvent
+} from "@fosscord/util";
import { Request, Response, Router } from "express";
const router = Router();
@@ -35,6 +40,8 @@ router.patch(
//@ts-ignore For some reason the client sends this as a boolean, even tho docs say its a number?
if (typeof body.visibility === "boolean") body.visibility = body.visibility ? 1 : 0;
+ //@ts-ignore For some reason the client sends this as a boolean, even tho docs say its a number?
+ if (typeof body.show_activity === "boolean") body.show_activity = body.show_activity ? 1 : 0;
connection.assign(req.body);
@@ -58,7 +65,7 @@ router.delete("/", route({}), async (req: Request, res: Response) => {
user_id: req.user_id,
external_id: connection_id,
type: connection_name,
- }
+ },
});
await Promise.all([
@@ -67,7 +74,7 @@ router.delete("/", route({}), async (req: Request, res: Response) => {
event: "USER_CONNECTIONS_UPDATE",
data: account,
user_id: req.user_id,
- })
+ }),
]);
return res.sendStatus(200);
|