Skip to content

Commit 5c77f5e

Browse files
committed
refactor(backend,web): make uri to /auth/google
also renames controller method from verifyGAuthSession to verifyGToken to more accurately represent what's happening. Compass doesn't maintain a persistent session with Google like it does with it's user's session (via Supertokens). Instead, it just passes the access token in requests
1 parent bcd99b2 commit 5c77f5e

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

packages/backend/src/auth/auth.routes.config.ts

+16-17
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,35 @@ import { CommonRoutesConfig } from "@backend/common/common.routes.config";
55
import authController from "./controllers/auth.controller";
66
import authMiddleware from "./middleware/auth.middleware";
77

8+
/**
9+
* Routes with the verifyIsDev middleware are
10+
* only available when running the app in dev,
11+
* as they are not called by production code.
12+
*/
813
export class AuthRoutes extends CommonRoutesConfig {
914
constructor(app: express.Application) {
1015
super(app, "AuthRoutes");
1116
}
1217

1318
configureRoutes(): express.Application {
1419
/**
15-
* Convenience routes for debugging (eg via Postman)
16-
*
17-
* Production code shouldn't call these
18-
* directly, which is why they're limited to devs only
20+
* Checks whether user's google access token is still valid
1921
*/
22+
this.app.route(`/api/auth/google`).get([
23+
verifySession(),
24+
//@ts-expect-error res.promise is not returning response types correctly
25+
authController.verifyGToken,
26+
]);
27+
2028
this.app
2129
.route(`/api/auth/session`)
2230
.all(authMiddleware.verifyIsDev)
23-
//@ts-ignore
31+
//@ts-expect-error res.promise is not returning response types correctly
32+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
2433
.post(authController.createSession)
2534
.get([
2635
verifySession(),
27-
//@ts-ignore
36+
//@ts-expect-error res.promise is not returning response types correctly
2837
authController.getUserIdFromSession,
2938
]);
3039

@@ -38,20 +47,10 @@ export class AuthRoutes extends CommonRoutesConfig {
3847
*/
3948
this.app.route(`/api/oauth/google`).post([
4049
authMiddleware.verifyGoogleOauthCode,
41-
//@ts-ignore
50+
//@ts-expect-error res.promise is not returning response types correctly
4251
authController.loginOrSignup,
4352
]);
4453

45-
/**
46-
* Ensures a user's google session is still valid, since
47-
* we need to occasionally sync events
48-
*/
49-
this.app.route(`/api/auth/session/gauth/verify`).get([
50-
verifySession(),
51-
//@ts-expect-error TODO: fix TS for this and other controller methods in this file
52-
authController.verifyGAuthSession,
53-
]);
54-
5554
return this.app;
5655
}
5756
}

packages/backend/src/auth/controllers/auth.controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class AuthController {
6666
res.promise({ userId });
6767
};
6868

69-
verifyGAuthSession = async (req: SessionRequest, res: Res_Promise) => {
69+
verifyGToken = async (req: SessionRequest, res: Res_Promise) => {
7070
try {
7171
const userId = req.session?.getUserId();
7272

packages/web/src/auth/gauth.util.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ import { ENV_WEB } from "@web/common/constants/env.constants";
33
export class GoogleOAuthSession {
44
static async verifySession() {
55
try {
6-
const res = await fetch(
7-
`${ENV_WEB.API_BASEURL}/auth/session/gauth/verify`,
8-
{
9-
method: "GET",
10-
credentials: "include",
11-
}
12-
);
6+
const res = await fetch(`${ENV_WEB.API_BASEURL}/auth/google`, {
7+
method: "GET",
8+
credentials: "include",
9+
});
1310

1411
if (!res.ok) return false;
1512

0 commit comments

Comments
 (0)