aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2024-07-10 03:08:17 +0100
committerGravatar Joe Banks <[email protected]>2024-07-10 03:08:17 +0100
commitf8758214f92d4eafa54349c3ac8ea033492f1eb6 (patch)
treed2d69d9971a3eeb4c3b63da2464668a5797fd3e8
parentMerge pull request #634 from python-discord/jb3/auth/popup-and-improvements (diff)
Set Sentry user data when authenticating
-rw-r--r--src/api/auth.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/api/auth.ts b/src/api/auth.ts
index 11baaa6..2dbcdae 100644
--- a/src/api/auth.ts
+++ b/src/api/auth.ts
@@ -4,6 +4,8 @@ import { AxiosResponse } from "axios";
import { startAuthorizing, finishAuthorizing } from "../slices/authorization";
import formsStore from "../store";
+import * as Sentry from "@sentry/react";
+
import APIClient from "./client";
const OAUTH2_CLIENT_ID = process.env.REACT_APP_OAUTH2_CLIENT_ID;
@@ -230,6 +232,10 @@ export async function refreshBackendJWT(): Promise<boolean> {
APIClient.post("/auth/refresh").then((response: AxiosResponse<AuthResult>) => {
cookies.set(CookieNames.Username, response.data.username, {sameSite: "strict", secure: PRODUCTION, path: "/", expires: new Date(3000, 1)});
+ Sentry.setUser({
+ username: response.data.username
+ });
+
const expiry = Date.parse(response.data.expiry);
setTimeout(refreshBackendJWT, ((expiry - Date.now()) / 1000 * 0.9));
}).catch(() => {
@@ -245,6 +251,7 @@ export async function refreshBackendJWT(): Promise<boolean> {
*/
export function clearAuth(): void {
const cookies = new Cookies();
+ Sentry.setUser(null);
cookies.remove(CookieNames.Scopes, {path: "/"});
cookies.remove(CookieNames.Username, {path: "/"});
}
@@ -278,6 +285,10 @@ export default async function authorize(scopes: OAuthScopes[] = [], disableFunct
const options: CookieSetOptions = {sameSite: "strict", secure: PRODUCTION, path: "/", expires: new Date(3000, 1)};
cookies.set(CookieNames.Username, backend_response.username, options);
+ Sentry.setUser({
+ username: backend_response.username,
+ });
+
options.maxAge = backend_response.maxAge;
cookies.set(CookieNames.Scopes, discord_response.cleanedScopes, options);