MCPcopy Create free account
hub / github.com/emwalker/digraph / onAuthSuccessFn

Function onAuthSuccessFn

client/src/server/auth/withGithub.ts:43–86  ·  view source on GitHub ↗
(environment: Environment)

Source from the content-addressed store, hash-verified

41}
42
43const onAuthSuccessFn = (environment: Environment) => async (
44 _arg0: any, _arg1: any, profile: IProfile, done: Done,
45) => {
46 console.log('GitHub login succeeded, getting viewer id')
47
48 // eslint-disable-next-line @typescript-eslint/naming-convention
49 const { displayName, emails, username, _json: { avatar_url } } = profile
50 const email = primaryOrFirstEmail(emails || [])
51 console.log(`User ${email || '(no email)'} logging in`)
52 if (!email || !username) return
53
54 const variables = {
55 input: {
56 githubAvatarUrl: avatar_url,
57 githubUsername: username,
58 name: displayName || 'Nemo',
59 primaryEmail: email,
60 serverSecret: process.env.DIGRAPH_SERVER_SECRET || 'keyboard cat',
61 },
62 }
63
64 const onCompleted = (payload: Payload) => {
65 if (!payload.createGithubSession) {
66 console.log('createGithubSession field missing from response:', payload)
67 done(null, null)
68 return
69 }
70
71 const { createGithubSession } = payload
72 const userEdge = createGithubSession?.userEdge
73 const sessionEdge = createGithubSession?.sessionEdge
74 console.log('User fetched from api, saving to session', userEdge, sessionEdge)
75 const id = userEdge && userEdge.node && userEdge.node.id
76 const sessionId = sessionEdge?.node?.id
77 done(null, { id, sessionId })
78 }
79
80 const onError = (error: Error) => {
81 console.log('Something happened:', error)
82 done(null, null)
83 }
84
85 createSession(environment, { variables, onCompleted, onError })
86}
87
88const registerEndpoints = registerEndpointsFn('github')
89

Callers 1

withGithub.tsFile · 0.85

Calls 2

primaryOrFirstEmailFunction · 0.85
createSessionFunction · 0.85

Tested by

no test coverage detected