Skip to content

Commit

Permalink
chore: daily development
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Dec 9, 2024
1 parent 4f21571 commit 4b95e0b
Showing 1 changed file with 56 additions and 57 deletions.
113 changes: 56 additions & 57 deletions packages/canyon-platform/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,65 @@ import GitLab from "next-auth/providers/gitlab";
import GitHub from "next-auth/providers/github";
import prisma from "@/lib/prisma";

export const { handlers, auth } = NextAuth(() => {
return {
providers: [
process.env.GITLAB_SERVER
? GitLab({
authorization: `${process.env.GITLAB_SERVER}/oauth/authorize?scope=read_user`,
token: `${process.env.GITLAB_SERVER}/oauth/token`,
userinfo: `${process.env.GITLAB_SERVER}/api/v4/user`,
})
: GitLab,
GitHub,
],
// secret: process.env.AUTH_SECRET,
callbacks: {
redirect: async () => {
return "/projects";
},
// 登陆的时候从gitlab获取用户信息
async signIn({ profile, account, user }) {
const userTest: any = {
export const { handlers, auth } = NextAuth({
trustHost: true,
providers: [
process.env.GITLAB_SERVER
? GitLab({
authorization: `${process.env.GITLAB_SERVER}/oauth/authorize?scope=read_user`,
token: `${process.env.GITLAB_SERVER}/oauth/token`,
userinfo: `${process.env.GITLAB_SERVER}/api/v4/user`,
})
: GitLab,
GitHub,
],
// secret: process.env.AUTH_SECRET,
callbacks: {
redirect: async () => {
return "/projects";
},
// 登陆的时候从gitlab获取用户信息
async signIn({ profile, account, user }) {
const userTest: any = {
accessToken: "accessToken",
refreshToken: "refreshToken",
username: profile?.username || profile?.login || "username",
nickname: user.name,
avatar: user.image || "/default-avatar.png",
email: user.email,
password: "123456",
favor: "",
createdAt: new Date(),
};

await prisma.user.upsert({
where: {
// @ts-ignore
id: String(account.provider + "-" + profile.id),
},
update: {
accessToken: "accessToken",
refreshToken: "refreshToken",
username: profile?.username || profile?.login || "username",
nickname: user.name,
avatar: user.image || "/default-avatar.png",
email: user.email,
password: "123456",
favor: "",
createdAt: new Date(),
};

await prisma.user.upsert({
where: {
// @ts-ignore
id: String(account.provider + "-" + profile.id),
},
update: {
accessToken: "accessToken",
refreshToken: "refreshToken",
},
create: {
// @ts-ignore
id: String(account.provider + "-" + profile.id),
...userTest,
},
});
return true;
},
jwt({ token, user, profile, account }) {
if (user) {
},
create: {
// @ts-ignore
token.id = String(account.provider + "-" + profile.id);
}
return token;
},
session({ session, token }) {
id: String(account.provider + "-" + profile.id),
...userTest,
},
});
return true;
},
jwt({ token, user, profile, account }) {
if (user) {
// @ts-ignore
session.user.id = token.id;
return session;
},
token.id = String(account.provider + "-" + profile.id);
}
return token;
},
session({ session, token }) {
// @ts-ignore
session.user.id = token.id;
return session;
},
};
},
});

0 comments on commit 4b95e0b

Please sign in to comment.