Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
bentwnghk committed Sep 21, 2024
2 parents 4922e3d + fc2e760 commit f808d5a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
13 changes: 0 additions & 13 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,6 @@ const nextConfig = {
],
source: '/apple-touch-icon.png',
},
{
headers: [
{
key: 'Content-Type',
value: 'application/javascript; charset=utf-8',
},
{
key: 'Content-Security-Policy',
value: "default-src 'self'; script-src 'self'",
},
],
source: '/sw.js',
},
];
},

Expand Down
16 changes: 11 additions & 5 deletions src/app/api/webhooks/casdoor/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ export const POST = async (req: Request): Promise<NextResponse> => {
const nextAuthUserService = new NextAuthUserService();
switch (action) {
case 'update-user': {
return nextAuthUserService.safeUpdateUser(extendedUser.id, {
avatar: extendedUser?.avatar,
email: extendedUser?.email,
fullName: extendedUser.displayName,
});
return nextAuthUserService.safeUpdateUser(
{
provider: 'casdoor',
providerAccountId: extendedUser.id,
},
{
avatar: extendedUser?.avatar,
email: extendedUser?.email,
fullName: extendedUser.displayName,
},
);
}

default: {
Expand Down
16 changes: 11 additions & 5 deletions src/app/api/webhooks/logto/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ export const POST = async (req: Request): Promise<NextResponse> => {
const nextAuthUserService = new NextAuthUserService();
switch (event) {
case 'User.Data.Updated': {
return nextAuthUserService.safeUpdateUser(data.id, {
avatar: data?.avatar,
email: data?.primaryEmail,
fullName: data?.name,
});
return nextAuthUserService.safeUpdateUser(
{
provider: 'logto',
providerAccountId: data.id,
},
{
avatar: data?.avatar,
email: data?.primaryEmail,
fullName: data?.name,
},
);
}

default: {
Expand Down
9 changes: 6 additions & 3 deletions src/server/services/nextAuthUser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ export class NextAuthUserService {
this.adapter = LobeNextAuthDbAdapter(serverDB);
}

safeUpdateUser = async (providerAccountId: string, data: Partial<UserItem>) => {
safeUpdateUser = async (
{ providerAccountId, provider }: { provider: string; providerAccountId: string },
data: Partial<UserItem>,
) => {
pino.info('updating user due to webhook');
// 1. Find User by account
// @ts-expect-error: Already impl in `LobeNextauthDbAdapter`
const user = await this.adapter.getUserByAccount({
provider: 'logto',
provider,
providerAccountId,
});

Expand All @@ -34,7 +37,7 @@ export class NextAuthUserService {
});
} else {
pino.warn(
`[logto]: Webhooks handler user update for "${JSON.stringify(data)}", but no user was found by the providerAccountId.`,
`[${provider}]: Webhooks handler user update for "${JSON.stringify(data)}", but no user was found by the providerAccountId.`,
);
}
return NextResponse.json({ message: 'user updated', success: true }, { status: 200 });
Expand Down

0 comments on commit f808d5a

Please sign in to comment.