-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubStrategies.controller.js
More file actions
48 lines (46 loc) · 1.52 KB
/
githubStrategies.controller.js
File metadata and controls
48 lines (46 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require("express");
const User = require("../Model/user.model");
module.exports = {
githubController: async (token, refreshToken, profile, done) => {
try {
let user = await User.findOne({ GithubId: profile.id });
if (!user) {
const newUser = new User({
GithubId: profile.id,
GithubUserName: profile.username,
GithubDisplayName: profile.displayName,
GitHubAvatar: profile._json.avatar_url,
Company: profile._json.company,
GitHubProtfolioa: profile._json.blog,
Location: profile._json.location,
GitHubBio: profile._json.bio,
PublicRepos: profile._json.public_repos,
GiHubFollowres: profile._json.followers,
GitHubFollowing: profile._json.following,
});
user = newUser;
await newUser.save();
const client = new PostHog(process.env.POSTHOG_API_KEY, {
host: "https://app.posthog.com",
});
client.capture({
distinctId: `${user.GithubUserName} successfully signed up to your version manager api.`,
event: "Authentication Event",
});
}
// const payLoad = user._id;
// const LogInToken = sign(payLoad, "VER123", {
// expiresIn: "24h",
// });
const data = {
user: user,
accessToken: token,
authToken: token,
};
// We Could save this access token in our frontend.
return done(null, data);
} catch (err) {
return done(err);
}
},
};