Skip to content

Commit

Permalink
fix(novu): a bunch of bugs & errors fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
finnc0 committed Mar 21, 2024
1 parent a7b919c commit 5d8fcab
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 35 deletions.
6 changes: 3 additions & 3 deletions apps/app/additional.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ declare namespace NodeJS {
NEXT_PUBLIC_RESOURCE_AUDIENCE: string;
NEXT_PUBLIC_ID_ISSUER: string;
NOVU_API_KEY: string;
NOVU_BACKEND_URL: string;
NOVU_WS_URL: string;
NOVU_APP_ID: string;
NEXT_PUBLIC_NOVU_BACKEND_URL: string;
NEXT_PUBLIC_NOVU_WS_URL: string;
NEXT_PUBLIC_NOVU_APP_ID: string;
}
}
33 changes: 21 additions & 12 deletions apps/app/app/api/logto/auth/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ export async function GET(req: Request, res: NextApiResponse) {
id: result.id,
},
});
try {
await Sub.createSub(
data.id,
data.email || '',
data.name || '',
data.image || '',
);
} catch (err) {}
} catch (err) {
// handle error
}
Expand Down Expand Up @@ -97,10 +89,6 @@ export async function GET(req: Request, res: NextApiResponse) {
},
},
});

try {
await Sub.createSub(data.userId, '', '', '');
} catch (err) {}
}
} catch (err) {
// handle error
Expand Down Expand Up @@ -130,6 +118,27 @@ export async function GET(req: Request, res: NextApiResponse) {
// WALDO MIGRATION LOGIC END---------END

// Novu Integration START--------START
const query = await prisma?.v2Account.findFirst({
where: {
providerAccountId:
logto_user.userInfo.identities[
Object.keys(logto_user.userInfo.identities)[0]
].userId,
},
include: {
user: true,
},
});
const user = query?.user;
try {
await Sub.createSub(
user?.id || '',
user?.email || '',
user?.name || '',
user?.image || '',
);
} catch (err) {}

// Novu Integration END--------END

return Response.redirect(process.env.BASE_URL);
Expand Down
10 changes: 6 additions & 4 deletions apps/app/app/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NotificationBell,
} from '@novu/notification-center';
//import useSite from '@site';
import NovuCustomStyling from './_styles/novu.css';
export default function Header() {
const s = useSession();
const session = s?.session;
Expand All @@ -34,10 +35,11 @@ export default function Header() {
</div>
<div className="flex ml-auto">
<NovuProvider
backendUrl={process.env.NOVU_BACKEND_URL}
socketUrl={process.env.NOVU_WS_URL}
subscriberId={session?.id}
applicationIdentifier={process.env.NOVU_APP_ID}
styles={NovuCustomStyling}
backendUrl={process.env.NEXT_PUBLIC_NOVU_BACKEND_URL}
socketUrl={process.env.NEXT_PUBLIC_NOVU_WS_URL}
subscriberId={'on-boarding-subscriber-id-123'}
applicationIdentifier={process.env.NEXT_PUBLIC_NOVU_APP_ID}
>
<PopoverNotificationCenter colorScheme={'dark'}>
{({ unseenCount }) => (
Expand Down
2 changes: 1 addition & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --port 3008",
"dev": "next dev --port 3005",
"build": "next build",
"start": "next start",
"lint": "next lint",
Expand Down
5 changes: 3 additions & 2 deletions packages/identity/utils/authUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ const createSession = async (): Promise<V2Session | Error | AxiosError> => {
const jwtData = logtoUserDataRes.claims;

const identityData =
logtoUserDataRes.userInfo.identities[
logtoUserDataRes.userInfo.identities[
Object.keys(logtoUserDataRes.userInfo.identities)[0]
];
const waldoUserDataReq = await axios.get(
process.env.NEXT_PUBLIC_BASE_URL + '/api/logto/usermeta',
);
const waldoUser: { blacklisted: boolean; id: string } = await waldoUserDataReq.data;
const waldoUser: { blacklisted: boolean; id: string } =
await waldoUserDataReq.data;

const scopeDataReq = await axios.get(accessTokenUrl, {
withCredentials: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/novu/novu.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Novu } from '@novu/node';

const config = {
backendUrl: process.env.NOVU_BACKEND_URL,
socketUrl: process.env.NOVU_WS_URL,
backendUrl: process.env.NEXT_PUBLIC_NOVU_BACKEND_URL,
socketUrl: process.env.NEXT_PUBLIC_NOVU_WS_URL,
};

const novu = new Novu(process.env.NOVU_API_KEY, config);
Expand Down
6 changes: 3 additions & 3 deletions packages/novu/process-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace NodeJS {
interface ProcessEnv {
[key: string]: string | undefined;
NOVU_API_KEY: string;
NOVU_BACKEND_URL: string;
NOVU_WS_URL: string;
NOVU_APP_ID: string;
NEXT_PUBLIC_NOVU_BACKEND_URL: string;
NEXT_PUBLIC_NOVU_WS_URL: string;
NEXT_PUBLIC_NOVU_APP_ID: string;
}
}
12 changes: 7 additions & 5 deletions packages/novu/subscribers/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ const createSub = async (
name: string,
avatar: string,
) => {
await novu.subscribers.identify(waldoId, {
email: email,
firstName: name,
avatar: avatar,
});
try {
const q = await novu.subscribers.identify(waldoId, {
//email: email,
firstName: name,
avatar: avatar,
});
} catch (err) {}
};

const sendTest = async () => {
Expand Down
6 changes: 3 additions & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"MAPI_APP_SECRET",
"MAPI_RESOURCE_URI",
"NOVU_API_KEY",
"NOVU_BACKEND_URL",
"NOVU_WS_URL",
"NOVU_APP_ID"
"NEXT_PUBLIC_NOVU_BACKEND_URL",
"NEXT_PUBLIC_NOVU_WS_URL",
"NEXT_PUBLIC_NOVU_APP_ID"
],
"outputs": ["dist/**", ".next/**", "out/**"]
},
Expand Down

0 comments on commit 5d8fcab

Please sign in to comment.