How could i make a firestore cloud function trigger on user login?











up vote
0
down vote

favorite












Cloud functions doesn't accept onLoging by default, how can i "bypass" this limitation so i can run a cloud function every time a user gets "online".



My thought so far is to run a create document on logIn and listen to it, but what happens when the user is not login in but using his last time session?



Do i run the same post request on the isLogged function ? that function can be run many times when the application is running, so is not optimal.



is running the function on app init (angular 7) the solution here?










share|improve this question


























    up vote
    0
    down vote

    favorite












    Cloud functions doesn't accept onLoging by default, how can i "bypass" this limitation so i can run a cloud function every time a user gets "online".



    My thought so far is to run a create document on logIn and listen to it, but what happens when the user is not login in but using his last time session?



    Do i run the same post request on the isLogged function ? that function can be run many times when the application is running, so is not optimal.



    is running the function on app init (angular 7) the solution here?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Cloud functions doesn't accept onLoging by default, how can i "bypass" this limitation so i can run a cloud function every time a user gets "online".



      My thought so far is to run a create document on logIn and listen to it, but what happens when the user is not login in but using his last time session?



      Do i run the same post request on the isLogged function ? that function can be run many times when the application is running, so is not optimal.



      is running the function on app init (angular 7) the solution here?










      share|improve this question













      Cloud functions doesn't accept onLoging by default, how can i "bypass" this limitation so i can run a cloud function every time a user gets "online".



      My thought so far is to run a create document on logIn and listen to it, but what happens when the user is not login in but using his last time session?



      Do i run the same post request on the isLogged function ? that function can be run many times when the application is running, so is not optimal.



      is running the function on app init (angular 7) the solution here?







      firebase-authentication google-cloud-firestore google-cloud-functions






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 12:31









      yejielw

      35




      35
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote














          You can create a function that triggers when a Firebase user is created using the functions.auth.user().onCreate() event handler:




          exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
          // ...
          });


          https://firebase.google.com/docs/functions/auth-events?hl=en-419



          but one alternative you have would be , to make a write operation in the client when user login.






          share|improve this answer





















          • but what if the user is already logged on the server.
            – yejielw
            Nov 11 at 15:02












          • You can code a script to make the operations one time, to get the neccesary data, if you need move data.
            – Mike Brian Olivera
            Nov 11 at 15:05












          • i would need it one time every time the user comes online
            – yejielw
            Nov 11 at 15:17










          • It's not possible from the server-side. look this: cloud.google.com/functions/docs/calling/firebase-auth
            – Mike Brian Olivera
            Nov 11 at 15:28


















          up vote
          0
          down vote













          Only you can define what a "session" is for your app. There is no universal definition that you can use to trigger a Cloud Function. Firebase Authentication won't help with this either, since users are logged in "forever", until your code explicitly logs them out (it automatically refreshes the user's auth token every hour).



          You're going to have to write your own code to figure this out by whatever specification you decide the user has "logged in" or "logged out".






          share|improve this answer





















          • figured that out, going to use an http call for the function in the end.
            – yejielw
            Nov 12 at 9:24











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248790%2fhow-could-i-make-a-firestore-cloud-function-trigger-on-user-login%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote














          You can create a function that triggers when a Firebase user is created using the functions.auth.user().onCreate() event handler:




          exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
          // ...
          });


          https://firebase.google.com/docs/functions/auth-events?hl=en-419



          but one alternative you have would be , to make a write operation in the client when user login.






          share|improve this answer





















          • but what if the user is already logged on the server.
            – yejielw
            Nov 11 at 15:02












          • You can code a script to make the operations one time, to get the neccesary data, if you need move data.
            – Mike Brian Olivera
            Nov 11 at 15:05












          • i would need it one time every time the user comes online
            – yejielw
            Nov 11 at 15:17










          • It's not possible from the server-side. look this: cloud.google.com/functions/docs/calling/firebase-auth
            – Mike Brian Olivera
            Nov 11 at 15:28















          up vote
          0
          down vote














          You can create a function that triggers when a Firebase user is created using the functions.auth.user().onCreate() event handler:




          exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
          // ...
          });


          https://firebase.google.com/docs/functions/auth-events?hl=en-419



          but one alternative you have would be , to make a write operation in the client when user login.






          share|improve this answer





















          • but what if the user is already logged on the server.
            – yejielw
            Nov 11 at 15:02












          • You can code a script to make the operations one time, to get the neccesary data, if you need move data.
            – Mike Brian Olivera
            Nov 11 at 15:05












          • i would need it one time every time the user comes online
            – yejielw
            Nov 11 at 15:17










          • It's not possible from the server-side. look this: cloud.google.com/functions/docs/calling/firebase-auth
            – Mike Brian Olivera
            Nov 11 at 15:28













          up vote
          0
          down vote










          up vote
          0
          down vote










          You can create a function that triggers when a Firebase user is created using the functions.auth.user().onCreate() event handler:




          exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
          // ...
          });


          https://firebase.google.com/docs/functions/auth-events?hl=en-419



          but one alternative you have would be , to make a write operation in the client when user login.






          share|improve this answer













          You can create a function that triggers when a Firebase user is created using the functions.auth.user().onCreate() event handler:




          exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
          // ...
          });


          https://firebase.google.com/docs/functions/auth-events?hl=en-419



          but one alternative you have would be , to make a write operation in the client when user login.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 14:58









          Mike Brian Olivera

          3651513




          3651513












          • but what if the user is already logged on the server.
            – yejielw
            Nov 11 at 15:02












          • You can code a script to make the operations one time, to get the neccesary data, if you need move data.
            – Mike Brian Olivera
            Nov 11 at 15:05












          • i would need it one time every time the user comes online
            – yejielw
            Nov 11 at 15:17










          • It's not possible from the server-side. look this: cloud.google.com/functions/docs/calling/firebase-auth
            – Mike Brian Olivera
            Nov 11 at 15:28


















          • but what if the user is already logged on the server.
            – yejielw
            Nov 11 at 15:02












          • You can code a script to make the operations one time, to get the neccesary data, if you need move data.
            – Mike Brian Olivera
            Nov 11 at 15:05












          • i would need it one time every time the user comes online
            – yejielw
            Nov 11 at 15:17










          • It's not possible from the server-side. look this: cloud.google.com/functions/docs/calling/firebase-auth
            – Mike Brian Olivera
            Nov 11 at 15:28
















          but what if the user is already logged on the server.
          – yejielw
          Nov 11 at 15:02






          but what if the user is already logged on the server.
          – yejielw
          Nov 11 at 15:02














          You can code a script to make the operations one time, to get the neccesary data, if you need move data.
          – Mike Brian Olivera
          Nov 11 at 15:05






          You can code a script to make the operations one time, to get the neccesary data, if you need move data.
          – Mike Brian Olivera
          Nov 11 at 15:05














          i would need it one time every time the user comes online
          – yejielw
          Nov 11 at 15:17




          i would need it one time every time the user comes online
          – yejielw
          Nov 11 at 15:17












          It's not possible from the server-side. look this: cloud.google.com/functions/docs/calling/firebase-auth
          – Mike Brian Olivera
          Nov 11 at 15:28




          It's not possible from the server-side. look this: cloud.google.com/functions/docs/calling/firebase-auth
          – Mike Brian Olivera
          Nov 11 at 15:28












          up vote
          0
          down vote













          Only you can define what a "session" is for your app. There is no universal definition that you can use to trigger a Cloud Function. Firebase Authentication won't help with this either, since users are logged in "forever", until your code explicitly logs them out (it automatically refreshes the user's auth token every hour).



          You're going to have to write your own code to figure this out by whatever specification you decide the user has "logged in" or "logged out".






          share|improve this answer





















          • figured that out, going to use an http call for the function in the end.
            – yejielw
            Nov 12 at 9:24















          up vote
          0
          down vote













          Only you can define what a "session" is for your app. There is no universal definition that you can use to trigger a Cloud Function. Firebase Authentication won't help with this either, since users are logged in "forever", until your code explicitly logs them out (it automatically refreshes the user's auth token every hour).



          You're going to have to write your own code to figure this out by whatever specification you decide the user has "logged in" or "logged out".






          share|improve this answer





















          • figured that out, going to use an http call for the function in the end.
            – yejielw
            Nov 12 at 9:24













          up vote
          0
          down vote










          up vote
          0
          down vote









          Only you can define what a "session" is for your app. There is no universal definition that you can use to trigger a Cloud Function. Firebase Authentication won't help with this either, since users are logged in "forever", until your code explicitly logs them out (it automatically refreshes the user's auth token every hour).



          You're going to have to write your own code to figure this out by whatever specification you decide the user has "logged in" or "logged out".






          share|improve this answer












          Only you can define what a "session" is for your app. There is no universal definition that you can use to trigger a Cloud Function. Firebase Authentication won't help with this either, since users are logged in "forever", until your code explicitly logs them out (it automatically refreshes the user's auth token every hour).



          You're going to have to write your own code to figure this out by whatever specification you decide the user has "logged in" or "logged out".







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 17:57









          Doug Stevenson

          67.3k87998




          67.3k87998












          • figured that out, going to use an http call for the function in the end.
            – yejielw
            Nov 12 at 9:24


















          • figured that out, going to use an http call for the function in the end.
            – yejielw
            Nov 12 at 9:24
















          figured that out, going to use an http call for the function in the end.
          – yejielw
          Nov 12 at 9:24




          figured that out, going to use an http call for the function in the end.
          – yejielw
          Nov 12 at 9:24


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248790%2fhow-could-i-make-a-firestore-cloud-function-trigger-on-user-login%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma