-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #515 from sparcs-kaist/google
Feat/ Google Login
- Loading branch information
Showing
13 changed files
with
8,979 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { z } from "zod"; | ||
import { OAuth2Client } from "google-auth-library"; | ||
import { env } from "@biseo/api/env"; | ||
import jwt from "jsonwebtoken"; | ||
|
||
const Token = z.object({ | ||
email: z.string(), | ||
}); | ||
|
||
export const gauthenticate = async (code: string): Promise<string | null> => { | ||
try { | ||
const logininfo = new OAuth2Client( | ||
env.GOOGLE_CLIENT, | ||
env.GOOGLE_SECRET, | ||
"postmessage", | ||
); | ||
const token = await logininfo.getToken(code); | ||
const mail = Token.parse(jwt.decode(token.tokens.id_token!)).email; | ||
const username = | ||
mail.split("@")[1] === "sparcs.org" ? mail.split("@")[0] : null; | ||
return username; | ||
} catch { | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { Router } from "express"; | ||
import { loginHandler } from "./login"; | ||
import { loginHandler, gLoginHandler } from "./login"; | ||
|
||
const router = Router(); | ||
|
||
router.post("/login", (req, res, next) => { | ||
loginHandler(req, res).catch(next); | ||
}); | ||
router.post("/glogin", (req, res, next) => { | ||
gLoginHandler(req, res).catch(next); | ||
}); | ||
|
||
export { router as authRouter }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.