|
@@ -11,6 +11,9 @@ import {
|
|
|
import {
|
|
import {
|
|
|
logout as _logout
|
|
logout as _logout
|
|
|
} from "../actions/auth/logout";
|
|
} from "../actions/auth/logout";
|
|
|
|
|
+import {
|
|
|
|
|
+ me as _me
|
|
|
|
|
+} from "../actions/auth/me";
|
|
|
import {
|
|
import {
|
|
|
AuthRequest
|
|
AuthRequest
|
|
|
} from "../middlewares/authMiddleware";
|
|
} from "../middlewares/authMiddleware";
|
|
@@ -117,4 +120,31 @@ export const logout = async (req: AuthRequest, res: Response): Promise<void> =>
|
|
|
code: 500,
|
|
code: 500,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+export const me = async (req: AuthRequest, res: Response): Promise<void> => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const context = req.context;
|
|
|
|
|
+
|
|
|
|
|
+ if (!context || !context.userId) {
|
|
|
|
|
+ res.status(401).json({
|
|
|
|
|
+ message: "Unauthorized", code: 401
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const result = await _me(context.userId);
|
|
|
|
|
+
|
|
|
|
|
+ res.status(result.code).json({
|
|
|
|
|
+ message: result.message,
|
|
|
|
|
+ code: result.code,
|
|
|
|
|
+ ...(result.payload && {
|
|
|
|
|
+ payload: result.payload
|
|
|
|
|
+ })
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ res.status(500).json({
|
|
|
|
|
+ message: "Server error", code: 500
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|