Skip to content

Commit 455c21e

Browse files
authored
Merge pull request #14 from oslabs-beta/auth
update user_created event to enforce payload type
2 parents e4d1cda + e650159 commit 455c21e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

examples_new/microservices/auth/src/controllers/auth-controller.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Request, Response } from 'express';
22
import axios, { AxiosError } from 'axios';
3-
import { BadRequestError, CurrentUserRequest, Events } from '@chronosrx/common';
3+
import { BadRequestError, CurrentUserRequest, EventTypes, Events } from '@chronosrx/common';
44
import { User } from '../models/user';
55
import { attachCookie } from '../util/attachCookie';
66

@@ -29,12 +29,17 @@ export const signup = async (req: Request, res: Response) => {
2929

3030
// TODO PUBLISH AN EVENT TO THE EVENT BUS - type USER_CREATED, with data of user - user.id & username
3131
// console.log('Publishing event USER_CREATED');
32+
33+
const event: Events = {
34+
type: EventTypes.USER_CREATED,
35+
payload: {
36+
id: newUser.id,
37+
username: newUser.username,
38+
},
39+
};
3240
try {
3341
await axios.post('http://localhost:3005/', {
34-
event: {
35-
type: Events.USER_CREATED,
36-
payload: newUser,
37-
},
42+
event,
3843
});
3944
} catch (err) {
4045
console.log(

0 commit comments

Comments
 (0)