diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 4ced49435..000000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,97 +0,0 @@ -name: Release -on: - push: - branches: - - main - -permissions: - contents: write -jobs: - check_if_version_upgraded: - name: Check if package version has been upgraded - runs-on: ubuntu-latest - outputs: - version: ${{ steps.version-updated.outputs.current-package-version }} - has_updated: ${{ steps.version-updated.outputs.has-updated }} - steps: - - uses: JiPaix/package-json-updated-action@v1.0.5 - id: version-updated - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - publish-js: - name: Publish package - runs-on: ubuntu-latest - needs: - - check_if_version_upgraded - # We create release only if the version in the package.json has been upgraded - if: | - needs.check_if_version_upgraded.outputs.has_updated == 'true' - steps: - - uses: actions/setup-node@v3 - with: - node-version: '18.x' - registry-url: 'https://registry.npmjs.org' - - uses: pnpm/action-setup@v2 - with: - version: 8 - run_install: false - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - ref: ${{ github.ref }} - - name: Install Dependencies - id: deps - run: | - pnpm install - - name: Build Release - id: build_release - run: | - pnpm build - - name: Sync README - run: | - git config user.name github-actions - git config user.email github-actions@github.com - if ! cmp -s ./README.md ./packages/auth/README.md; then - if git diff --quiet HEAD ./README.md; then - cp ./packages/auth/README.md ./README.md - else - cp ./README.md ./packages/auth/README.md - fi - git add . - git commit -m "Sync README.md" - git push origin ${{ github.ref }} - fi - - name: Run Tests - id: tests - run: | - pnpm test - - name: Publish Release - if: steps.tests.outcome == 'success' - run: | - if [ "$NODE_AUTH_TOKEN" = "" ]; then - echo "You need a NPM_TOKEN secret in order to publish." - false - fi - echo //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN} > .npmrc - EXTRA_ARGS="" - if [[ $VERSION == *"alpha."* ]] || [[ $VERSION == *"beta."* ]] || [[ $VERSION == *"rc."* ]]; then - echo "Is pre-release version" - EXTRA_ARGS="$EXTRA_ARGS --dist-tag next" - fi - npx lerna publish ${VERSION} --yes --force-publish $EXTRA_ARGS - echo 🎉 Published to NPM https://www.npmjs.com/package/@localfirst/auth/v/${VERSION} - env: - VERSION: ${{ needs.check_if_version_upgraded.outputs.version }} - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Tag release - if: steps.tests.outcome == 'success' - uses: softprops/action-gh-release@v1 - with: - name: v${{ needs.check_if_version_upgraded.outputs.version }} - tag_name: v${{ needs.check_if_version_upgraded.outputs.version }} - target_commitish: main - generate_release_notes: true - draft: false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/demos/automerge-repo-todos/src/components/CreateTeam.tsx b/demos/automerge-repo-todos/src/components/CreateTeam.tsx index 5b0ff2ee5..fbaff09fa 100644 --- a/demos/automerge-repo-todos/src/components/CreateTeam.tsx +++ b/demos/automerge-repo-todos/src/components/CreateTeam.tsx @@ -1,11 +1,10 @@ -import * as Auth from '@localfirst/auth' import cx from 'classnames' import { useState } from 'react' import type { SharedState } from '../types' import { initializeAuthRepo } from '../util/initializeAuthRepo' import { storeRootDocumentIdOnTeam } from '../util/storeRootDocumentIdOnTeam' import { type SetupCallback } from './FirstUseSetup' -import { createDevice } from '../util/createDevice' +import { createUserAndDevice } from '../util/createDevice' export const CreateTeam = ({ userName, onSetup }: Props) => { const [teamName, setTeamName] = useState('') @@ -13,9 +12,8 @@ export const CreateTeam = ({ userName, onSetup }: Props) => { const createTeam = async () => { if (!teamName || teamName.length === 0) return - // Create new user and device - const user = Auth.createUser(userName) - const device = createDevice(user.userId) + // A founding user's id derives from their founding device. + const { user, device } = createUserAndDevice(userName) // Create repo and auth provider const { auth, repo } = await initializeAuthRepo({ user, device }) diff --git a/demos/automerge-repo-todos/src/components/JoinTeam.tsx b/demos/automerge-repo-todos/src/components/JoinTeam.tsx index 0255bad67..40c2e8e40 100644 --- a/demos/automerge-repo-todos/src/components/JoinTeam.tsx +++ b/demos/automerge-repo-todos/src/components/JoinTeam.tsx @@ -1,7 +1,7 @@ -import * as Auth from '@localfirst/auth' import cx from 'classnames' +import type * as Auth from '@localfirst/auth' import { useState } from 'react' -import { createDevice } from '../util/createDevice' +import { createDevice, createUserAndDevice } from '../util/createDevice' import { initializeAuthRepo } from '../util/initializeAuthRepo' import { parseInvitationCode } from '../util/parseInvitationCode' import type { SetupCallback } from './FirstUseSetup' @@ -9,12 +9,10 @@ import type { SetupCallback } from './FirstUseSetup' export const JoinTeam = ({ joinAs, userName, onSetup }: Props) => { const [invitationCode, setInvitationCode] = useState('') - const getUserAndDevice = () => { + const getUserAndDevice = (): { user?: Auth.UserWithSecrets; device: Auth.DeviceWithSecrets } => { if (joinAs === 'MEMBER') { - // Create new user and device - const user = Auth.createUser(userName) as Auth.UserWithSecrets - const device = createDevice(user.userId) - return { user, device } + // A new member's id derives from the device that founds their identity. + return createUserAndDevice(userName) } else { // Create new device (our user has already been created on another device) const device = createDevice(userName) // we'll temporarily use the userName instead of the userId @@ -25,8 +23,8 @@ export const JoinTeam = ({ joinAs, userName, onSetup }: Props) => { const { user, device } = getUserAndDevice() const { auth, repo } = await initializeAuthRepo({ user, device }) - const { shareId, invitationSeed } = parseInvitationCode(invitationCode) - auth.addInvitation({ shareId, invitationSeed, userName }) + const { expectedTeamId, shareId, invitationSeed } = parseInvitationCode(invitationCode) + auth.addInvitation({ expectedTeamId, shareId, invitationSeed, userName }) // Once we're admitted, we'll get the Team data and our User object auth.once('joined', ({ team, user }) => { diff --git a/demos/automerge-repo-todos/src/components/TeamAdmin.tsx b/demos/automerge-repo-todos/src/components/TeamAdmin.tsx index 94bd64aba..16192b155 100644 --- a/demos/automerge-repo-todos/src/components/TeamAdmin.tsx +++ b/demos/automerge-repo-todos/src/components/TeamAdmin.tsx @@ -1,5 +1,4 @@ import { UnixTimestamp } from '@localfirst/auth' -import { getShareId } from '@localfirst/auth-provider-automerge-repo' import ClipboardJS from 'clipboard' import { MutableRefObject, useEffect, useRef, useState } from 'react' import { useAuth } from '../hooks/useAuth' @@ -10,7 +9,6 @@ export const TeamAdmin = () => { const [state, setState] = useState(SHOW_MEMBERS) const [invitationCode, setInvitationCode] = useState() - const maxUsesSelect = useRef() as MutableRefObject const expirationSelect = useRef() as MutableRefObject const { user, team } = useAuth() @@ -29,16 +27,14 @@ export const TeamAdmin = () => { }, [copyInvitationCodeButton, invitationCode]) const createInvitationCode = (seed: string) => { - const shareId = getShareId(team) - setInvitationCode(`${shareId}${seed}`) + setInvitationCode(`${team.id}:${seed}`) } const inviteMembers = () => { - const maxUses = Number(maxUsesSelect.current.value) const now = Date.now() const expirationMs = Number(expirationSelect.current.value) * 1000 const expiration = (now + expirationMs) as UnixTimestamp - const { seed } = team.inviteMember({ maxUses, expiration }) + const { seed } = team.inviteMember({ expiration }) createInvitationCode(seed) setState(SHOWING_MEMBER_INVITE) } @@ -110,18 +106,6 @@ export const TeamAdmin = () => {

Invite members

- +

This invitation can be used by multiple people until it expires or is revoked.