Retrieve user profile information using solid node client?

I want to fetch my username, user photo, my organization name,role, address from my pod using expressJS. I am using rdflib. But my name is returning null. I am following rdflib.
A Note: I am accessing my express website from docker
My code:

// declaration part 
const {SolidNodeClient} = require("Solid-Node-Client");
const client = new SolidNodeClient();
const store = $rdf.graph();
const me = store.sym('my webId');
const profile = me.doc() 
const VCARD = new $rdf.Namespace(‘http://www.w3.org/2006/vcard/ns#‘);
const FOAF = $rdf.Namespace('http://xmlns.com/foaf/0.1/');

//code part
let name = store.any(me, VCARD(‘fn’)) || store.any(me, FOAF(‘name’));
console.log("user name: ", name);

but name is showing null on console.

a) Your capitalization is wrong, it should be require(“solid-node-client”)
b) You didn’t load the profile. You need to create a fetcher and use it to load the profile as I showed you here: Can not access node solid development server localhost - #13 by Tapu106.

Here is your code, but fixed with the changes mentioned above. It prints my name.

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://jeff-zucker.solidcommunity.net/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);                                       
});                                                                             

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.