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 29e7ee7 commit d62a8da
Showing 1 changed file with 59 additions and 53 deletions.
112 changes: 59 additions & 53 deletions packages/canyon-platform/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,69 @@ import NextAuth from "next-auth";
import GitLab from "next-auth/providers/gitlab";
import GitHub from "next-auth/providers/github";
import prisma from "@/lib/prisma";
console.log(process.env.AUTH_SECRET, "process.env.AUTH_SECRET");
export const { handlers, auth } = NextAuth({
providers: [
GitLab({
// authorization: "https://git.com/oauth/authorize?scope=read_user",
// token: "https://git.com/oauth/token",
// userinfo: "https://git.com/api/v4/user",
}),
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: {
export const { handlers, auth } = NextAuth(async () => {
const s = await prisma.sysSetting.findMany({
where: {},
});
console.log(JSON.stringify(s));
return {
providers: [
GitLab({
// authorization: "https://git.com/oauth/authorize?scope=read_user",
// token: "https://git.com/oauth/token",
// userinfo: "https://git.com/api/v4/user",
}),
GitHub,
],
// secret: s,
callbacks: {
redirect: async () => {
return "/projects";
},
// 登陆的时候从gitlab获取用户信息
async signIn({ profile, account, user }) {
const userTest: any = {
accessToken: "accessToken",
refreshToken: "refreshToken",
},
create: {
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) {
// @ts-ignore
id: String(account.provider + "-" + profile.id),
...userTest,
},
});
return true;
},
jwt({ token, user, profile, account }) {
if (user) {
token.id = String(account.provider + "-" + profile.id);
}
return token;
},
session({ session, token }) {
// @ts-ignore
token.id = String(account.provider + "-" + profile.id);
}
return token;
},
session({ session, token }) {
// @ts-ignore
session.user.id = token.id;
return session;
session.user.id = token.id;
return session;
},
},
},
};
});

0 comments on commit d62a8da

Please sign in to comment.