So just to stress on it, there is no way to recover a deleted Server Key. Before even deleting a Server Key in the Google Developers Console, a dialog appears saying:
This credential will be deleted immediately and permanently. Once deleted, it can no longer be used to make API requests.
I don't wanna lose my users.
You only deleted the Server Key which is used for Authorization. The 401 error is only an auth error that says that your sender has a problem authenticating. Not the end of a project.
You don't lose the users so long as you still have the registration tokens and it's corresponding Sender ID(s) exists.
The way that you have to do this now is for you to import your Google Developer Console project to Firebase Console, since as mentioned in the docs:
Starting from Sept. 2016 new server key can only be created in the Firebase Console using the Cloud Messaging tab of the Settings panel. Existing projects that need to create a new server key can be imported in the Firebase console without affecting their existing configuration.
Steps on how to import your project is like so:
- Go to your Firebase Console and click on IMPORT PROJECT.
- Select the project you want to import and your country.
- Click on ADD FIREBASE. After this, the new Project should be active.
- Then on left-side panel, click on the gear button and select Project Settings.
- Then go to the Cloud-Messaging Tab.
401 Authorization error is so common this past few months. Don't panic. See my answer here.