Source

lib/util/getSession.js

  1. // Includes
  2. const settings = require('../../settings.json')
  3. const options = require('../options.js')
  4. // Args
  5. exports.optional = ['jar']
  6. // Docs
  7. /**
  8. * 🔐 Get the .ROBLOSECURITY cookie from the jar.
  9. * @category Utility
  10. * @alias getSession
  11. * @param {CookieJar=} jar - The cookie jar containing the .ROBLOSECURITY cookie.
  12. * @returns {string}
  13. * @example const noblox = require("noblox.js")
  14. * // Login using your cookie.
  15. * const cookie = await noblox.getSession()
  16. **/
  17. // Define
  18. exports.func = function (args) {
  19. const jar = args.jar || options.jar
  20. if (settings.session_only) {
  21. if (typeof jar === 'string') {
  22. return jar
  23. }
  24. return jar.session
  25. } else {
  26. const cookies = jar.getCookies('https://roblox.com')
  27. for (let i = 0; i < cookies.length; i++) {
  28. const element = cookies[i]
  29. if (element.key === '.ROBLOSECURITY') {
  30. return element.value
  31. }
  32. }
  33. return ''
  34. }
  35. }