Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ so typically a hand-written user interface will be chosen over a generic machine
These panes are used in the Data Browser - see mashlib
[https://github.com/linkeddata/mashlib](https://github.com/linkeddata/mashlib)

When panes are hosted through mashlib and use solid-logic authentication, ensure the refresh worker is served same-origin. The worker export and runtime override contract are documented in solid-logic:
https://github.com/solidos/solid-logic#worker-asset-and-runtime-configuration

Currently the panes available include:

- A default pane which lists the properties of any object
Expand Down
19 changes: 10 additions & 9 deletions dev/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,22 @@ window.onload = async () => {
console.log('document ready')
// registerPanes((cjsOrEsModule: any) => paneRegistry.register(cjsOrEsModule.default || cjsOrEsModule))
paneRegistry.register(require('contacts-pane'))
await authSession.handleIncomingRedirect({
restorePreviousSession: true
})
const session = await authSession
if (!session.info.isLoggedIn) {
await solidLogicSingleton.authn.checkUser()
const session = authSession
const isLoggedIn = session?.info?.isLoggedIn ?? session?.isActive ?? Boolean(session?.webId)
if (!isLoggedIn) {
console.log('The user is not logged in')
const loginBanner = document.getElementById('loginBanner');
if (loginBanner) {
loginBanner.innerHTML = '<button onclick="login()">Log in</button>';
}
} else {
console.log(`Logged in as ${session.info.webId}`)
const loggedWebId = session?.info?.webId || session?.webId
console.log(`Logged in as ${loggedWebId}`)

const loginBanner = document.getElementById('loginBanner');
if (loginBanner) {
loginBanner.innerHTML = `Logged in as ${session.info.webId} <button onclick="logout()">Log out</button>`;
loginBanner.innerHTML = `Logged in as ${loggedWebId} <button onclick="logout()">Log out</button>`;
}
}
addLayoutButtons()
Expand All @@ -155,8 +155,9 @@ window.logout = () => {
window.location.href = ''
}
window.login = async function () {
const session = await authSession
if (!session.info.isLoggedIn) {
const session = authSession
const isLoggedIn = session?.info?.isLoggedIn ?? session?.isActive ?? Boolean(session?.webId)
if (!isLoggedIn) {
const issuer = prompt('Please enter an issuer URI', 'https://solidcommunity.net')
if (issuer) {
await authSession.login({
Expand Down
4 changes: 3 additions & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default {
'\\.svg\\?raw$': '<rootDir>/test/__mocks__/fileMock.js',
'\\.(svg)$': '<rootDir>/test/__mocks__/fileMock.js',
'\\.(png|jpe?g|gif|webp|avif)$': '<rootDir>/test/__mocks__/fileMock.js',
'\\.css$': '<rootDir>/test/__mocks__/styleMock.js'
'\\.css$': '<rootDir>/test/__mocks__/styleMock.js',
'solid-logic': '<rootDir>/../solid-logic/src/index.ts',
'solid-oidc-client-browser': '<rootDir>/test/mocks/solid-oidc-client-browser.ts'
},
setupFilesAfterEnv: ['./test/helpers/setup.ts'],
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'],
Expand Down
2 changes: 1 addition & 1 deletion src/mainPage/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const applyMenuCollapsedState = (navMenu: HTMLElement | null): void => {
updateCollapseButtonPosition(navMenu, collapseBtn)
}

const isLoggedIn = (): boolean => Boolean(authSession?.info?.isLoggedIn)
const isLoggedIn = (): boolean => Boolean(authSession?.isActive)

const ensureMenuSkeleton = () => {
menuCollapsed = loadMenuCollapsedState()
Expand Down
57 changes: 57 additions & 0 deletions test/mocks/solid-oidc-client-browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
type Listener = (...args: any[]) => void

class EventEmitterLike {
private listeners: Record<string, Listener[]> = {}

on(event: string, listener: Listener): void {

Check failure on line 6 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (22)

Missing space before function parentheses

Check failure on line 6 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (24)

Missing space before function parentheses
const list = this.listeners[event] || []
list.push(listener)
this.listeners[event] = list
}

emit(event: string, ...args: any[]): void {

Check failure on line 12 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (22)

Missing space before function parentheses

Check failure on line 12 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (24)

Missing space before function parentheses
const list = this.listeners[event] || []
list.forEach(listener => listener(...args))
}
}

export class Session {
info: { webId?: string, isLoggedIn: boolean } = { isLoggedIn: false }
webId?: string
isActive = false
events = new EventEmitterLike()

addEventListener(event: string, listener: Listener): void {

Check failure on line 24 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (22)

Missing space before function parentheses

Check failure on line 24 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (24)

Missing space before function parentheses
this.events.on(event, listener)
}

async handleIncomingRedirect(): Promise<void> {

Check failure on line 28 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (22)

Missing space before function parentheses

Check failure on line 28 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (24)

Missing space before function parentheses
return

Check failure on line 29 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (22)

Unnecessary return statement

Check failure on line 29 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (24)

Unnecessary return statement
}

async handleRedirectFromLogin(): Promise<void> {

Check failure on line 32 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (22)

Missing space before function parentheses

Check failure on line 32 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (24)

Missing space before function parentheses
return

Check failure on line 33 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (22)

Unnecessary return statement

Check failure on line 33 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (24)

Unnecessary return statement
}

async restore(): Promise<void> {

Check failure on line 36 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (22)

Missing space before function parentheses

Check failure on line 36 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (24)

Missing space before function parentheses
return

Check failure on line 37 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (22)

Unnecessary return statement

Check failure on line 37 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (24)

Unnecessary return statement
}

async login(): Promise<void> {

Check failure on line 40 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (22)

Missing space before function parentheses

Check failure on line 40 in test/mocks/solid-oidc-client-browser.ts

View workflow job for this annotation

GitHub Actions / build (24)

Missing space before function parentheses
return
}

async logout(): Promise<void> {
this.info = { isLoggedIn: false }
this.webId = undefined
this.isActive = false
}

fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
return globalThis.fetch(input, init)
}

authFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
return globalThis.fetch(input, init)
}
}
14 changes: 12 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,18 @@
] /* List of folders to include type definitions from. */,
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"preserveSymlinks": true, /* Keep symlinks unresolved to avoid duplicate rdflib type identities in local linked dev. */
/* baseUrl + paths below are for local integrated dev only.
They force a single rdflib type identity when solid-panes is linked to local solid-logic/solid-ui.
Both options are deprecated in TS6+ but remain functional until TS7.
See solid-ui README: Local Integrated Development for context. */
"ignoreDeprecations": "6.0",
"baseUrl": ".",
"paths": {
"rdflib": ["node_modules/rdflib"],
"rdflib/*": ["node_modules/rdflib/*"]
}

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
Expand Down
Loading