Retrieve user profile information using solid node client?

hey Jeff, I hopped on this. But I haven’t the correct setup I guess. I’ ll attach my html, my js and the error message. Can you see what I missed ? (perhaps I’ll have to setup express… setup webpack… work with rdflib-save… the require already doesn’t work…)

<!DOCTYPE html>
<html lang = "de">
<head>
<meta charset = "utf-8">
<title>print name</title>
</head>
<body>
  <h5>output goes to console</h5>
 <script src = "index.js"></script>
<!-- <img src="favicon.ico" onload="execCode()" > -->
<p>----</p>
<!-- <p id = "something"></p> -->
</body>
</html>
const $rdf = require('rdflib');                                                 
const {SolidNodeClient} = require("solid-node-client");                         
const client = new SolidNodeClient();                                           
const store = $rdf.graph();                                                     
const fetcher = $rdf.fetcher(store,{fetch:client.fetch.bind(client)});          
const me = store.sym('https://testpro.solidweb.org/profile/card#me'); 
const profile = me.doc()                                                        
const VCARD = $rdf.Namespace('http://www.w3.org/2006/vcard/ns#');           
const FOAF = $rdf.Namespace('http://xmlns.com/foaf/0.1/');                      
                                                                                
fetcher.load(profile).then( ()=>{                                                    
  let name = store.any(me, VCARD("fn")) || store.any(me, FOAF("name"));         
  console.log("user name: ", name.value);                                       
});

thanx
Bildschirmfoto_2021-07-04_18-43-57

@ewingson - Solid Node Client is a client for Nodejs (command-line and console-based scripts). It is not intended to work in a browser althoug it can work in conjunction with a browser in an Electron environment,

okay… I now have done npm install rdflib --save in the dir of the js. how do I execute the script ?

node scriptname

works. !! thanx !!

1 Like

Thanks! I can successfully access my name. But the code you provided in Can not access node solid development server localhost returns “Can not read property value of null”
My code:

const { SolidNodeClient } = require("solid-node-client");
const client = new SolidNodeClient();
const $rdf = require("rdflib");
const store = $rdf.graph();
const fetcher = $rdf.fetcher(store,{fetch:client.fetch.bind(client)});
const FoaF = $rdf.Namespace('http://xmlns.com/foaf/0.1');
const VCARD = $rdf.Namespace("http://www.w3.org/2006/vcard/ns#");
const pim = $rdf.Namespace('http://www.w3.org/ns/pim/space#');
 
router.get("/loginSSI", async function (req, res) {
  console.log("done");
  try {
    console.log("try ");
    let ses = await client.login({
      idp: YOUR_IDENTITY_PROVIDER, // e.g. https://solidcommunity.net
      username: "username",
      password: "password",
    });
    console.log(ses.webId);
    const me = $rdf.sym(ses.webId);
    console.log("me: ", me);
 
    const profile = $rdf.sym(ses.webId).doc();
    console.log("profile: ", profile);
    await fetcher.load(profile);
    let myPrefs = store.any(me,pim("preferencesFile"));
    await fetcher.load(myPrefs);
    let mbox = store.any( me , FoaF('mbox'));
    console.log("mbox: ",mbox.value); // can not read property 'value' of null
    let token = uuidv4();
    req.session.token = token;
    req.session.save((err) => {
      auth.validTokens.push(token);
      res.redirect("/");
    });
    
  } catch (error) {
    console.log(error.message);
  }
});

I think you first need to see if you can login from the command-line. Try this:

const {SolidNodeClient} = require("solid-node-client");                         
const client  = new SolidNodeClient();                                          
                                                                                
async function login(credentials){                                              
  console.log('logging in ...');                                                
  let session = await client.login(credentials);                                
  if( session.isLoggedIn ) {                                                    
    console.log(`logged in as <${session.WebID}>`);                             
    return session;                                                             
  }                                                                             
  else {                                                                        
    console.log(`Could not login to <${credentials.idp}>`);                     
  }                                                                             
}                                                                               
login({                                                                         
  idp: "YOUR_IDENTITY_PROVIDER", // e.g. https://solidcommunity.net             
  username: "username",                                                         
  password: "password",                                                         
});

You wrote :

208770640_239966797677614_7192060768026886758_n

I am sorry, I can not debug your server or your express. I can help you with solid-node-client. But please run the script I provided and tell me the results.

Oh sorry. the login function is working fine. It returns my webId.

You were able to login to your local NSS?

No. I am using my solid Community Pod. I’ve tried with my local NSS but was unsuccessful.

You tried the script I provided using the login credentials for your local NSS? What were the results? (results of the script, I don’t care what the server log is)

Sorry if I didn’t understand you correctly. I tried the script you provided with my solidCommunity pod and it returns my webId.

Isn’t your aim to use solid node client to access your local NSS pod?

Yeah. But due to some issues, I am accessing solidCommunity instead of my local NSS temporarily.

Please try the script I provided with your local NSS details. It is the only way to find out what the problem is.

Ok. I’ll get back to you soon. Thanks.

Good luck!

I ran your script. It returns

TypeError: Cannot read property '‘isLoggedIn’ of null

I have added information on how I installed local NSS on my laptop.In my pc I can use my local pod to login in existing solid app.But when I use in docker “https://localhost:8443” it returns above error. In docker I am using node v10. I can’t upgrade my node due to dependency issue.

I can run NSS fine in node 12. You should troubleshoot with NSS. Neither rdflib nor solid-node-client can run in node 10 so if you stay with node 10, you simply can not use those libraries. What OS are you using?

You might also want to investigate NVM which lets you easily switch back and forth between node versions.