Hello!
I was wondering if it was possible to retrieve user data from Gaia storage on the server for the purpose of server side rendering data-hydrated web pages?
I’m building an app with Next.js and I wanted to be able to include spiderable open graph meta data from the user’s blockstack profile / public storage for rich sharing. Normally, I’d just make a network request in Next.js’ server-side getInitialProps
but any calls to blockstack seem to need window
to be defined.
I’m wondering if it is possible to retrieve this data server side. In a similar vain, it would be useful to have a server side check for isUserLoggedIn
for auth-based redirect logic.
Any advice on this topic would be greatly appreciated!
1 Like
I believe this is theoretically possible but we haven’t completed default support for Node given conversation and workaround guidance here: https://github.com/blockstack/blockstack.js/issues/500
1 Like
For server side rendering you probably don’t need to use blockstack.js
The following steps worked for me (https://github.com/friedger/matrix-blockstack-password-provider/blob/master/matrix_blockstack_password_provider/matrix_blockstack_password_provider.py#L89)
- lookup the name using a public node
- parse the zone file and retrieve the value you need
3 Likes
Yeah, currently it’s not super possible using the default functions within blockstack.js. After the new version is released which will allow new storage strategies/drivers to be used, I could see a cookie storage provider working where the user would auth once, then that data would be saved into a cookie which could be read by the node server and then you’d use that to do your fetches within getInitialProps
.
However, if you’re just trying to get non-app-specific data, there are public apis you can fetch from listed here: core.blockstack.org.