MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / findOrCreateGithubUser

Function findOrCreateGithubUser

apps/webapp/app/models/user.server.ts:64–150  ·  view source on GitHub ↗
({
  email,
  authenticationProfile,
  authenticationExtraParams,
}: FindOrCreateGithub)

Source from the content-addressed store, hash-verified

62}
63
64export async function findOrCreateGithubUser({
65 email,
66 authenticationProfile,
67 authenticationExtraParams,
68}: FindOrCreateGithub): Promise<LoggedInUser> {
69 const name = authenticationProfile._json.name;
70 let avatarUrl: string | undefined = undefined;
71 if (authenticationProfile.photos[0]) {
72 avatarUrl = authenticationProfile.photos[0].value;
73 }
74 const displayName = authenticationProfile.displayName;
75 const authProfile = authenticationProfile
76 ? (authenticationProfile as unknown as Prisma.JsonObject)
77 : undefined;
78 const authExtraParams = authenticationExtraParams
79 ? (authenticationExtraParams as unknown as Prisma.JsonObject)
80 : undefined;
81
82 const authIdentifier = `github:${authenticationProfile.id}`;
83
84 const existingUser = await prisma.user.findUnique({
85 where: {
86 authIdentifier,
87 },
88 });
89
90 const existingEmailUser = await prisma.user.findUnique({
91 where: {
92 email,
93 },
94 });
95
96 if (existingEmailUser && !existingUser) {
97 const user = await prisma.user.update({
98 where: {
99 email,
100 },
101 data: {
102 authenticationProfile: authProfile,
103 authenticationExtraParams: authExtraParams,
104 avatarUrl,
105 authIdentifier,
106 },
107 });
108
109 return {
110 user,
111 isNewUser: false,
112 };
113 }
114
115 if (existingEmailUser && existingUser) {
116 const user = await prisma.user.update({
117 where: {
118 id: existingUser.id,
119 },
120 data: {},
121 });

Callers 1

findOrCreateUserFunction · 0.85

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…