Not able to login to solid server through app

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:

Login

when 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

Are you creating a Web bundle or just including the listed JS files in your HTML?

I don’t have enough information here to help much, so if you can share the entire app via github or similar I might be able to see what the issue is.

@ happybeing
Thanks for the quick reply, I will share the code on github so you can get a better look of it.

1 Like

@happybeing
This is the link to the repository:

Thanks for sharing the code. I’m not familiar with this way of working (with express) so am not sure how this is supposed to work.

The error doesn’t surprise me, because I don’t see how the require in your routes is supposed to work. What I’m used to is either:

  • creating a Web bundle using webify, or webpack etc to process the require statements, and then including that bundle using <script src='mybundle.js'></script > in your HTML, or
  • running the code using node from the command line

I can’t see what you are doing here because it doesn’t seem to be either of those.

Thanks for the response.
Is there any simple examples that you could share so i can get a hang of it.

Are you trying to create a Web app or something else?

I am trying to create a web app

Take a look at https://solid.inrupt.com/ which has a tutorial for a Web app, but also at the Solid React app generator, then ask more here or in the Solid gitter chat https://gitter.im/solid/chat whenever you need help.

I haven’t done the tutorial or used the generator myself yet, but think they are a good way to get started.

Welcome and good luck :smile:

1 Like

@happybeing
Thanks a lot for the time and patience to explain all these, I will definitely look into those and reach out if i get into a dead end.

1 Like