You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Sails项目中集成sails-auth库失败,启动触发TypeError错误

Fixing TypeError: sails.getBaseurl is not a function with sails-auth

Hey there, that error pops up because of a version compatibility issue between sails-auth and your current Sails.js version. Let's break down why it's happening and how to fix it:

Why this happens

The sails.getBaseurl() method was removed or renamed in newer Sails.js versions (post-v1.x, roughly), but sails-auth hasn't been updated in a while—it still relies on this old method. When you run sails lift, the auth hook tries to call a function that no longer exists in your Sails instance.

Solutions to try

1. Downgrade Sails.js to a compatible version

This is the quickest fix if you don't mind using an older Sails release that works with sails-auth:

  • Uninstall your current Sails version:
    npm uninstall sails
    
  • Install a compatible Sails v1.x release (the last version range sails-auth supports):
    npm install sails@1.x --save
    
  • Restart your app:
    sails lift
    

2. Patch the sails-auth code manually

If you want to keep your current Sails version, you can modify the sails-auth hook to use the modern replacement for getBaseurl():

  • Navigate to the auth hook file in your node_modules: /home/egwuenu/Desktop/shopper/server/node_modules/sails-auth/dist/api/hooks/auth/index.js
  • Search for every instance of sails.getBaseurl() and replace it with sails.config.baseUrl
  • Important: Make sure you've set baseUrl in your Sails config! Add this to config/custom.js (or the appropriate environment config file):
    module.exports.custom = {
      baseUrl: 'http://localhost:1337' // Replace with your app's actual base URL
    };
    
  • Save the changes and run sails lift again

⚠️ Note: Patching node_modules directly is temporary—any npm install or npm update will overwrite your changes. For a permanent fix, fork the sails-auth repo, apply the patch there, and install your forked version via npm.

3. Switch to a maintained auth alternative

Since sails-auth is no longer actively maintained, you might want to use a more up-to-date solution long-term:

  • Integrate Passport.js directly into your Sails app (Sails has official guidance on this)
  • Use a maintained wrapper like passport-sails

内容的提问来源于stack exchange,提问作者lauragift21

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:18:22