# Not able to login to solid server through app

**URL:** <https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734>\
**Category:** Solid App Development FAQs\
**Created:** [April 24, 2019, 10:38am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734 "2019-04-24T10:38:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajayngnb](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ajayngnb/32/689_2.png) [@ajayngnb](https://forum.solidproject.org/u/ajayngnb)\
**Post date:** [April 24, 2019, 10:38am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734/1 "2019-04-24T10:38:45Z")

</div>

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](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](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

---

<div class="post-metadata">

**Author:** ![happybeing](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/happybeing/32/59_2.png) [@happybeing](https://forum.solidproject.org/u/happybeing)\
**Post date:** [April 24, 2019, 10:48am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734/2 "2019-04-24T10:48:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ajayngnb](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ajayngnb/32/689_2.png) [@ajayngnb](https://forum.solidproject.org/u/ajayngnb)\
**Post date:** [April 24, 2019, 10:50am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734/3 "2019-04-24T10:50:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ajayngnb](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ajayngnb/32/689_2.png) [@ajayngnb](https://forum.solidproject.org/u/ajayngnb)\
**Post date:** [April 24, 2019, 10:57am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734/4 "2019-04-24T10:57:31Z")

</div>

@happybeing  
This is the link to the repository:

> **[ajayngnb/solid-login](https://github.com/ajayngnb/solid-login)**
>
> solid-login. Contribute to ajayngnb/solid-login development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![happybeing](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/happybeing/32/59_2.png) [@happybeing](https://forum.solidproject.org/u/happybeing)\
**Post date:** [April 24, 2019, 11:18am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734/5 "2019-04-24T11:18:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ajayngnb](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ajayngnb/32/689_2.png) [@ajayngnb](https://forum.solidproject.org/u/ajayngnb)\
**Post date:** [April 24, 2019, 11:21am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734/6 "2019-04-24T11:21:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![happybeing](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/happybeing/32/59_2.png) [@happybeing](https://forum.solidproject.org/u/happybeing)\
**Post date:** [April 24, 2019, 11:22am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734/7 "2019-04-24T11:22:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ajayngnb](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ajayngnb/32/689_2.png) [@ajayngnb](https://forum.solidproject.org/u/ajayngnb)\
**Post date:** [April 24, 2019, 11:23am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734/8 "2019-04-24T11:23:31Z")

</div>

I am trying to create a web app

---

<div class="post-metadata">

**Author:** ![happybeing](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/happybeing/32/59_2.png) [@happybeing](https://forum.solidproject.org/u/happybeing)\
**Post date:** [April 24, 2019, 11:30am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734/9 "2019-04-24T11:30:03Z")

</div>

Take a look at [https://solid.inrupt.com/](https://solid.inrupt.com/) which has a [tutorial](https://solid.inrupt.com/docs/app-on-your-lunch-break) for a Web app, but also at the [Solid React app generator](https://solid.inrupt.com/docs/writing-solid-apps-with-react), then ask more here or in the Solid gitter chat [https://gitter.im/solid/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 😄

---

<div class="post-metadata">

**Author:** ![ajayngnb](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ajayngnb/32/689_2.png) [@ajayngnb](https://forum.solidproject.org/u/ajayngnb)\
**Post date:** [April 24, 2019, 11:35am UTC](https://forum.solidproject.org/t/not-able-to-login-to-solid-server-through-app/1734/10 "2019-04-24T11:35:14Z")

</div>

@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.
