mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 13:05:08 +09:00
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import { User } from "@prisma/client";
|
|
import { GitHubProfile } from "remix-auth-github";
|
|
import { GoogleProfile } from "remix-auth-google";
|
|
import { ensureUserCookie } from "../session";
|
|
import { prisma } from "./prisma.server";
|
|
|
|
export const createOrLoginWithGithub = async (
|
|
profile: GitHubProfile
|
|
): Promise<User> => {
|
|
const user = await prisma.user.findUnique({
|
|
where: { email: profile._json.email },
|
|
});
|
|
|
|
if (user) {
|
|
return user;
|
|
}
|
|
|
|
const newUser = prisma.user.create({
|
|
data: {
|
|
email: profile._json.email,
|
|
username: profile.displayName,
|
|
image: profile._json.avatar_url,
|
|
provider: profile.provider,
|
|
},
|
|
});
|
|
|
|
return newUser;
|
|
};
|
|
|
|
export const createOrLoginWithGoogle = async (
|
|
profile: GoogleProfile
|
|
): Promise<User> => {
|
|
const user = await prisma.user.findUnique({
|
|
where: { email: profile._json.email },
|
|
});
|
|
|
|
if (user) {
|
|
return user;
|
|
}
|
|
|
|
const newUser = prisma.user.create({
|
|
data: {
|
|
email: profile._json.email,
|
|
username: profile.displayName,
|
|
image: profile._json.avatar_url,
|
|
provider: profile.provider,
|
|
},
|
|
});
|
|
|
|
return newUser;
|
|
};
|