MCPcopy Index your code
hub / github.com/app-generator/api-server-nodejs / githubOauthHandler

Function githubOauthHandler

src/controllers/auth.controller.ts:8–32  ·  view source on GitHub ↗
(
    req: Request,
    res: Response,
  )

Source from the content-addressed store, hash-verified

6import { createUserWithToken } from '../services/user.service';
7
8export const githubOauthHandler = async (
9 req: Request,
10 res: Response,
11 ) => {
12 try {
13 const code = req.query.code as string;
14
15 if (!code) {
16 return res.json({error: 'authorization code not provided'})
17 }
18
19 // Get access_token using code
20 const { access_token } = await getGithubOathToken({ code });
21
22 // Get user details using access token
23 const userData = await getGithubUser({access_token});
24
25 const returnedUser = await createUserWithToken(userData)
26
27 res.json({user: returnedUser})
28
29 } catch (err: any) {
30 res.json({'error': err.message})
31 }
32 };
33

Callers

nothing calls this directly

Calls 3

getGithubOathTokenFunction · 0.90
getGithubUserFunction · 0.90
createUserWithTokenFunction · 0.90

Tested by

no test coverage detected