Skip to content

Latest commit

 

History

History
35 lines (29 loc) · 1.04 KB

using-in-browser.md

File metadata and controls

35 lines (29 loc) · 1.04 KB

back to README

Using solid-file-client in a browser

<!-- IMPORT SOLID-AUTH-CLIENT AND SOLID-FILE-CLIENT LIBRARIES
-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist-lib/solid-auth-client.bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/window/solid-file-client.bundle.js"></script>

<script>
// INSTANTIATE AUTH AND FILE-CLIENT OBJECTS
//
    const auth = solid.auth
    const fc   = new SolidFileClient(auth)

// DEFINE A URI THAT CONTAINS A POPUP LOGIN SCREEN
//
    const popUri = 'https://solidcommunity.net/common/popup.html'

// USE THE AUTH OBJECT TO LOGIN AND CHECK THE SESSION
// USE THE FILE-CLIENT OBJECT TO READ AND WRITE
//
    async function run(){
        let session = await auth.currentSession()
        if (!session) { session = await auth.popupLogin({ popupUri:popUri }) }
        console.log(`Logged in as ${session.webId}.`)
        let content = await fc.readFile( someUrl )
        console.log(content)
    }

    ...