MrDarkside
                (Tomi Tomion)
              
                
              
                  
                  
              1
              
             
            
              I need to insert a script into Admin > Customize > CSS/HTML. It has to run only if a user not logged in
I tried Discourse.User.current() but got a deprecation warning:
Deprecation notice: Import the User class instead of using User (deprecated since Discourse 2.4.0) (removal in Discourse 2.6.0)
Are there other ways to find it out?
             
            
              
              
              
            
            
           
          
            
              
                Canapin
                (Coin-coin le Canapin)
              
              
                  
                  
              2
              
             
            
              <script type="text/discourse-plugin" version="0.8">
const user = api.getCurrentUser();
if(user) {
    // do stuff
}
</script>
             
            
              
              
              3 Likes
            
            
           
          
            
              
                MrDarkside
                (Tomi Tomion)
              
              
                  
                  
              3
              
             
            
              Oh so I have access to api object there, that’s nice. Thanks!
             
            
              
              
              
            
            
           
          
            
              
                MrDarkside
                (Tomi Tomion)
              
              
                  
                  
              4
              
             
            
              <script>
    const user = api.getCurrentUser();
    console.log(user)
</script>
Uncaught ReferenceError: api is not defined
Oopsie
             
            
              
              
              
            
            
           
          
            
              
                loginerror
                (Maciej Kuźmicz)
              
              
                  
                  
              5
              
             
            
              You need to specify the type of your script as:
<script type="text/discourse-plugin" version="0.8">
             
            
              
              
              4 Likes
            
            
           
          
            
              
                MrDarkside
                (Tomi Tomion)
              
              
                  
                  
              6
              
             
            
              No mistakes, but nothing happens either. Anyway, thanks, at least now I know which way to dig
             
            
              
              
              
            
            
           
          
            
              
                system
                (system)
                  Closed 
              
              
                  
                  
              7
              
             
            
              This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.