Create URL to get user notification
This commit is contained in:
parent
53b96d61fe
commit
69bf416dd0
8 changed files with 104 additions and 20 deletions
|
@ -19,6 +19,7 @@ export class AuthenticateController extends BaseController {
|
|||
this.userRegister();
|
||||
this.userLogin();
|
||||
this.forgotPassword();
|
||||
this.notificationRecent();
|
||||
}
|
||||
|
||||
//Try to login with an admin token
|
||||
|
@ -250,4 +251,35 @@ export class AuthenticateController extends BaseController {
|
|||
})();
|
||||
});
|
||||
}
|
||||
|
||||
private notificationRecent() {
|
||||
this.App.options("/user/notifications/recent", (res: HttpResponse, req: HttpRequest) => {
|
||||
this.addCorsHeaders(res);
|
||||
res.end();
|
||||
});
|
||||
|
||||
this.App.get("/user/notifications/recent", (res: HttpResponse, req: HttpRequest) => {
|
||||
|
||||
(async () => {
|
||||
|
||||
res.onAborted(() => {
|
||||
console.warn('Forgot password request was aborted');
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await adminApi.getNotification();
|
||||
res.writeStatus("200 OK");
|
||||
this.addCorsHeaders(res);
|
||||
res.end(JSON.stringify(response.data));
|
||||
} catch (err) {
|
||||
res.writeStatus("400 KO");
|
||||
this.addCorsHeaders(res);
|
||||
res.end(JSON.stringify({
|
||||
message: err.message
|
||||
}));
|
||||
}
|
||||
|
||||
})();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,6 +165,13 @@ class AdminApi {
|
|||
headers: {"Authorization": `${ADMIN_API_TOKEN}`}
|
||||
});
|
||||
}
|
||||
|
||||
getNotification() {
|
||||
return Axios.get(`${ADMIN_API_URL}/notifications/recent`,
|
||||
{
|
||||
headers: {"Authorization": `${ADMIN_API_TOKEN}`}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const adminApi = new AdminApi();
|
||||
|
|
|
@ -6,8 +6,12 @@ import {adminApi, AdminApiData} from "../Services/AdminApi";
|
|||
|
||||
class JWTTokenManager {
|
||||
|
||||
public createJWTToken(userUuid: string) {
|
||||
return Jwt.sign({userUuid: userUuid}, SECRET_KEY, {expiresIn: '200d'}); //todo: add a mechanic to refresh or recreate token
|
||||
public createJWTToken(userUuid: string, email?: string, name?: string) {
|
||||
return Jwt.sign({
|
||||
userUuid: userUuid,
|
||||
email: email || null,
|
||||
name: name || null,
|
||||
}, SECRET_KEY, {expiresIn: '200d'}); //todo: add a mechanic to refresh or recreate token
|
||||
}
|
||||
|
||||
public async getUserUuidFromToken(token: unknown): Promise<string> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue