Skip to content

Commit ac70b39

Browse files
committed
Update name and logo in clientid.jsonld during build (solidcouch#117)
Also update some remaining occurences of SolidCouch to actual community name at runtime Follow-up of solidcouch#112
1 parent 84da968 commit ac70b39

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@
6767
"scripts": {
6868
"start": "react-scripts start",
6969
"prebuild": "yarn build:community-info",
70-
"build": "dotenv -e .env.build -- react-scripts build && node scripts/build-clientid.js",
71-
"postbuild": "yarn build:update-manifest",
70+
"build": "dotenv -e .env.build -- react-scripts build",
71+
"postbuild": " yarn build:update-clientid && yarn build:update-manifest",
7272
"build:cname": "node scripts/add-cname.js",
7373
"build:community-info": "dotenv -e .env -c -- node --loader ts-node/esm scripts/update-community-info.mts",
7474
"build:update-manifest": "dotenv -e .env.build -- node --loader ts-node/esm scripts/update-manifest.mts",
75+
"build:update-clientid": "dotenv -e .env.build -- node scripts/build-clientid.js",
7576
"test": "react-scripts test",
7677
"eject": "react-scripts eject",
7778
"preanalyze": "yarn build",

scripts/build-clientid.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ content = content.replaceAll(
2121
'https://app.solidcouch.org', // or a default
2222
)
2323

24+
// update name and logo if available
25+
const contentObject = JSON.parse(content, 'utf8')
26+
const communityName = process.env.REACT_APP_COMMUNITY_NAME_UNSAFE
27+
const communityLogo = process.env.REACT_APP_COMMUNITY_LOGO
28+
if (communityName) {
29+
contentObject.client_name = communityName
30+
// eslint-disable-next-line no-console
31+
console.log('Updated name in ClientID:', communityName)
32+
}
33+
if (communityLogo) {
34+
contentObject.logo_uri = communityLogo
35+
// eslint-disable-next-line no-console
36+
console.log('Updated logo in ClientID:', communityLogo)
37+
}
38+
content = JSON.stringify(contentObject, null, 2)
39+
2440
// Write the content to the output file
2541
fs.writeFileSync(clientIdPath, content, 'utf8')
2642

src/components/Join/Join.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ExternalButtonLink } from 'components/Button/Button'
44
import type { IssuerConfig } from 'config'
55
import { useConfig } from 'config/hooks'
66
import { actions } from 'features/login/loginSlice'
7+
import { useReadCommunity } from 'hooks/data/useCommunity'
78
import { ChangeEvent, Fragment, ReactNode, useMemo, useState } from 'react'
89
import Modal from 'react-modal'
910
import styles from './Join.module.scss'
@@ -33,7 +34,10 @@ const RegistrationButton = ({
3334
}
3435

3536
const useTabs = () => {
36-
const { oidcIssuers } = useConfig()
37+
const { oidcIssuers, communityId } = useConfig()
38+
39+
const community = useReadCommunity(communityId)
40+
const communityName = community.name || 'SolidCouch'
3741

3842
const tabs = useMemo(
3943
() => [
@@ -42,7 +46,7 @@ const useTabs = () => {
4246
label: 'Show me some providers!',
4347
content: (
4448
<>
45-
Here are some Pod providers that work with SolidCouch:
49+
Here are some Pod providers that work with {communityName}:
4650
<ul>
4751
{oidcIssuers
4852
.filter(iss => iss.registration)
@@ -148,7 +152,7 @@ const useTabs = () => {
148152
),
149153
},
150154
],
151-
[oidcIssuers],
155+
[communityName, oidcIssuers],
152156
)
153157

154158
return tabs
@@ -158,6 +162,10 @@ export const Join = () => {
158162
const [modalOpen, setModalOpen] = useState(false)
159163
const [selectedTab, setSelectedTab] = useState<string>()
160164

165+
const { communityId } = useConfig()
166+
const community = useReadCommunity(communityId)
167+
const communityName = community.name || 'SolidCouch'
168+
161169
const handleTabChange = (event: ChangeEvent<HTMLInputElement>) => {
162170
setSelectedTab(event.target.value)
163171
}
@@ -177,7 +185,7 @@ export const Join = () => {
177185
>
178186
<div className={styles.container}>
179187
<div className={styles.content}>
180-
To join SolidCouch, you need a{' '}
188+
To join {communityName}, you need a{' '}
181189
<a
182190
href="https://solidproject.org/users/get-a-pod"
183191
target="_blank"

src/components/SignIn/SignIn.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Button } from 'components'
44
import { guessIssuer } from 'components/SignIn/oidcIssuer'
55
import { useConfig } from 'config/hooks'
66
import { actions, selectLastSelectedIssuer } from 'features/login/loginSlice'
7+
import { useReadCommunity } from 'hooks/data/useCommunity'
78
import { useState } from 'react'
89
import { useForm } from 'react-hook-form'
910
import Modal from 'react-modal'
@@ -12,7 +13,7 @@ import styles from './SignIn.module.scss'
1213
Modal.setAppElement('#root')
1314

1415
export const SignIn = () => {
15-
const { oidcIssuers } = useConfig()
16+
const { oidcIssuers, communityId } = useConfig()
1617
const [modalOpen, setModalOpen] = useState(false)
1718
const [longList, setLongList] = useState(false)
1819

@@ -25,6 +26,8 @@ export const SignIn = () => {
2526

2627
const dispatch = useAppDispatch()
2728

29+
const community = useReadCommunity(communityId)
30+
2831
// sign in on selecting a provider
2932
const handleSelectIssuer = async (oidcIssuer: string) => {
3033
const prevIssuer = lastIssuer ?? ''
@@ -35,7 +38,7 @@ export const SignIn = () => {
3538
await login({
3639
oidcIssuer,
3740
redirectUrl: new URL('/', window.location.href).toString(),
38-
clientName: 'SolidCouch',
41+
clientName: community.name || 'SolidCouch',
3942
clientId:
4043
process.env.NODE_ENV === 'development' &&
4144
!process.env.REACT_APP_ENABLE_DEV_CLIENT_ID

src/pages/HospexSetup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const HospexSetup = ({
6161
const [selectedHospexDocument, setSelectedHospexDocument] = useState('')
6262
const [addToExisting, setAddToExisting] = useState<boolean>()
6363
const newHospexDocument = `${storage}hospex/${communityContainer}/card`
64+
6465
const handleClickSetup = async () => {
6566
setIsSaving(true)
6667
if (
@@ -124,7 +125,7 @@ export const HospexSetup = ({
124125

125126
return (
126127
<div>
127-
<header>Welcome to SolidCouch!</header>
128+
<header>Welcome to {community.name || 'SolidCouch'}!</header>
128129
<div>We would like to set up your Pod:</div>
129130
<ul>
130131
<li>{!isMember && `join community ${communityId}`}</li>

0 commit comments

Comments
 (0)