Skip to content

Commit

Permalink
Fix server authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
phisn committed May 13, 2024
1 parent 607b75d commit 839c405
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
6 changes: 0 additions & 6 deletions packages/server/src/api/user/user-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,22 @@ export const userRouter = router({
)
.query(async ({ input: { code }, ctx: { oauth, env, db } }) => {
try {
console.error(1)
const { access_token } = await oauth.validateAuthorizationCode(code, {
credentials: env.AUTH_GOOGLE_CLIENT_SECRET,
authenticateWith: "request_body",
})
console.error(2)

const userInfoRequest = await fetch(
`https://www.googleapis.com/oauth2/v1/userinfo?access_token=${access_token}`,
)

console.error(3)

if (!userInfoRequest.ok) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Failed to fetch user info",
})
}

console.error(4)

const userInfo = z
.object({
email: z.string(),
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/framework/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const createContext =
"https://accounts.google.com/o/oauth2/auth",
"https://accounts.google.com/o/oauth2/token",
{
redirectURI: env.CLIENT_URL,
redirectURI: env.CLIENT_URL.split(",").at(-1),
},
),
env,
Expand Down
1 change: 1 addition & 0 deletions packages/server/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ port = 3002

[vars]
CLIENT_URL = "https://new.rocketgame.app,https://rust-game.rocket-game.pages.dev,https://polyburn.com"
API_URL="https://api.polyburn.com"

[[d1_databases]]
migrations_dir = "drizzle"
Expand Down

0 comments on commit 839c405

Please sign in to comment.