Hi,
I am new to solid, I have been working on linux administration and devops tools like ansible, chef. i have been going through all the tutorials and sample applications available for building solid apps. I have been trying to build an application based on solid using nodeJS. I am having a bit of trouble setting up to log in using solid.
Well here is my code:
This is my app.js file :
const express = require(‘express’)
const expressLayout = require(‘express-ejs-layouts’)
// Express server configuration
const PORT = process.env.PORT || 3000
const app = express()
// EJS
app.use(expressLayout)
app.set(‘view engine’, ‘ejs’)
// Bodyparser
app.use(express.urlencoded({ extended: false }))
// Routes
app.use(’/’, require(’./routes/index’))
// Start Express Server
app.listen(PORT, () => {
console.log(Application running on https://localhost:${PORT}
)
})
This is my router.js file:
const express = require(‘express’)
const router = express.Router()
const solid = require(‘solid-auth-cli’).solid
const auth = require(‘solid-auth-cli’).auth
router.get(’/’, (req, res) => {
res.render(‘welcome’)
})
// Solid login handle
router.post(’/login’, (req, res, next) => {
console.log(‘Logging in’)
var idp =“https://solid.community”
var username = “ajaykumard”
var pass = “”
login(idp).then(session => {
console.log(Logged in as ${session.webId}
)
}, e => console.log("Error logging in: "+e))
async function login(idp, username, pass) {
var session = await solid.auth.currentSession()
if(!session) session = await solid.auth.login(idp)
return session;
}
})
module.exports = router
This is my welcome.ejs page:
Loginwhen i try this code i am getting an error as :
Logging in
Error logging in: TypeError: Cannot read property ‘auth’ of undefined
I followed the example from https://www.npmjs.com/package/solid-auth-cli
Can someone please let me know what mistake am i doing here, and what is the best approach that i can follow.
Thank you