The discussion revolves around marking notifications as read via the Discourse API from an external application. duranmla seeks to use the notifications/mark-read endpoint but encounters issues, suspecting a CORS configuration problem due to a custom plugin overriding the default CORS settings. Falco advises that marking notifications should be done from the backend for security reasons, as client-side actions may not ensure proper authentication. sam confirms that API access mirrors what’s possible on the website, but emphasizes the risks of client-side operations. Ultimately, duranmla resolves the issue by removing the custom plugin, restoring the default CORS configuration, and enabling proper API functionality.
I am working in a project that has discourse integrated with several apps, by now, I need to be able to allow one of those external apps to mark notifications from discourse as read but of course, consuming the API.
For instance, if I try to hit the notifications/mark-read endpoint I will get
Nevertheless, I will stress that I have already manage basic things as CORS config and token handling from outside (For instance my component is able to login/logout the user and pull user notifications).
The idea is that this custom component has a button to “Mark all as read”
I have also seen this “clear_notifications” method
And it while it looks like the thing I can use it seems to not be exposed or available for the usage outside discourse app?
Thanks for the answer, nevertheless, just to double check: It means there is no built-in endpoint that I can use from outside front-end in order to mark the notifications as read?
I should add that functionality myself on the backend and then consume that new endpoint to mark notifications as read. It is like that?
In my very specific case the problem was related to the fact that I had one plugin in place that rewrite the class Discourse::Cors method def self.apply_headers(cors_origins, env, headers), thus, I didn’t have the behaviour of the Discourse source code defined at discourse/config/initializers/008-rack-cors.rb at main · discourse/discourse · GitHub but instead some custom thing that I don’t even need.
Once I remove the plugin I get back the core definition for CORS and everything works as expected.