diff --git a/src/pages/authentication/building-todo-app.md b/src/pages/authentication/building-todo-app.md index 8ca20f6c..bed878c8 100644 --- a/src/pages/authentication/building-todo-app.md +++ b/src/pages/authentication/building-todo-app.md @@ -21,7 +21,7 @@ running and reviewing the code for a "Todos" web app built with Stacks authentic This app highlights the following platform functionality: -- Generate Secret Key with associated Stacks username to authenticate app +- Generate Secret Key with associated BNS username to authenticate app - Add, edit and delete encrypted app data with Gaia - Decrypt data on Gaia for public sharing by URL - Unauthenticate and re-authenticate app with Secret Key @@ -73,8 +73,7 @@ You should see the app's landing page: ### Step 1: Choose **Get started** to start onboarding into the app. The app displays a standardized introductory modal using -[Stacks Connect](https://github.com/blockstack/ux/tree/master/packages/connect), a JavaScript -library that makes it easy to integrate Stacks authentication into the UI of any web app. +[Stacks Auth](https://github.com/blockstack/stacks.js/tree/master/packages/auth) ![The Stacks Connect Modal](/images/todos-intro.png) @@ -84,7 +83,7 @@ that triggers this modal in [`src/components/Signin.jsx`](https://github.com/blo ```js // src/components/Signin.jsx -import { useConnect } from '@stacks/connect'; +import { useConnect } from '@stacks/auth'; export const Signin = () => { const { doOpenAuth } = useConnect(); @@ -95,7 +94,7 @@ export const Signin = () => { This component imports the [React hook](https://reactjs.org/docs/hooks-overview.html) [`useConnect`](https://github.com/blockstack/ux/blob/master/packages/connect/src/react/hooks/use-connect.ts) -from the Stacks Connect library. +from the Stacks Auth library. `useConnect` returns many helper functions such as [`doOpenAuth`](https://github.com/blockstack/ux/blob/master/packages/connect/src/react/hooks/use-connect.ts#L33), @@ -112,16 +111,14 @@ The modal displays the app's name and icon as configured in // src/components/App.jsx appDetails: { - name: 'Blockstack App', + name: 'Stacks App', icon: window.location.origin + '/favicon.ico' } ``` This component loads the [`UserSession`](https://blockstack.github.io/stacks.js/classes/usersession.html) -module from a second Stacks library called [@stacks/auth](https://github.com/blockstack/stacks.js/), -which complements Stacks Connect by providing an API for many protocol-level operations, such as for -authentication and storage. +module from `@stacks/auth` ```js import { UserSession } from '@stacks/auth'; @@ -145,7 +142,7 @@ export const appConfig = new AppConfig(['store_write', 'publish_data']); The `appDetails` and `userSession` objects are joined by the callback function [`finished`](https://github.com/blockstack/stacks-todos/blob/master/src/components/App.jsx#L31) -in configuring Stacks Connect for authentication with the `authOptions` object: +in configuring Stacks Auth for authentication with the `authOptions` object: ```js // src/components/App.jsx diff --git a/src/pages/authentication/connect.md b/src/pages/authentication/connect.md deleted file mode 100644 index 85850ecd..00000000 --- a/src/pages/authentication/connect.md +++ /dev/null @@ -1,187 +0,0 @@ ---- -title: Stacks Connect -description: Learn what Connect is and how to integrate it into an app. -experience: beginners -duration: 15 minutes -images: - large: /images/pages/connect.svg - sm: /images/pages/connect-sm.svg ---- - -## Introduction - -Stacks Connect is a JavaScript library for integrating Stacks authentication, data storage, and smart contracts into your app. - -The library empowers you to: - -- Register new users with a pre-built onboarding flow that quickly educates them as to the privacy benefits of using your app with Stacks authentication and provisions a "Secret Key" that secures their identity and data against the Stacks blockchain. -- Authenticate users when they return to your app using that same Secret Key. -- Prompt users to sign transactions with smart contracts as written in Clarity and published to the Stacks blockchain. - -## How does this compare to `stacks.js`? - -Connect uses stacks.js under the hood to construct and decode authentication requests. It provides pre-built onboarding UI that educates users as to how your app is more secure for having implemented Stacks authentication. You will need to use `stack.js` packages for storage and transactions. - -## Start building with Stacks Connect - -Head over to the [to-do app tutorial](/authentication/building-todo-app) to learn how to build apps with Stacks Connect. For interaction with Stacks accounts and smart contracts with Stacks Connect see the [transaction sigining section](/smart-contracts/signing-transactions). - -## Installation - -With yarn: - -```bash -yarn add @stacks/connect -``` - -With npm: - -```bash -npm install --save @stacks/connect -``` - -## Usage - -### AuthOptions - -Every major method you'll use with `connect` requires you to pass some options, like the name and icon of your app, and what to do when authentication is finished. In practice, this means you need to define these options, and pass them to the various API methods. - -The exact interface you'll use [is defined as](https://github.com/blockstack/ux/blob/master/packages/connect/src/auth.ts#L17:L39): - -```typescript -export interface AuthOptions { - redirectTo: string; - onFinish: (payload: FinishedData) => void; - sendToSignIn?: boolean; - userSession?: UserSession; - appDetails: { - name: string; - icon: string; - }; -} -``` - -| parameter | type | default | optional | description | -| ------------ | ----------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| redirectTo | string | | false | The path in your app where users go after sign in. | -| appDetails | object | | false | an object which includes `appName: string` and `appIcon: string`. This will speed up the process of loading your app's information during onboarding. | -| onFinish | function | | false | A callback that can be invoked after authentication. This prevents having to do a whole page refresh in a new tab. One argument is passed to this callback, which is an object with `userSession` included. If included, then the `redirectTo` path is ignored, and the user will be logged in automatically. | -| finished | function | | false | **Deprecated**. Use `onFinish`. | -| sendToSignIn | boolean | false | true | Whether the user should go straight to the 'sign in' flow (false) or be presented with the 'sign up' flow (true) instead. | -| userSession | UserSession | | true | pass a `UserSession` instance to use for authentication. If it's not passed, `@stacks/connect` will create one for you. | -| userSession | UserSession | | false | pass a `UserSession` instance to use for authentication. If it's not passed, `@stacks/connect` will create one for you. | - -### In ES6 (non-React) apps - -If you aren't using React, or just want a simpler API, then you can use the `showConnect` method. - -```jsx -import { showConnect } from '@stacks/connect'; - -const authOptions = { - /** See docs above for options */ -}; -showConnect(authOptions); -``` - -#### Sign In - -To send the user straight to sign in, include `sendToSignIn: true` in your `authOptions`. - -### Using a hosted version of `@stacks/connect` - -If you aren't using ES6 imports, you can still use `connect`! We package the library so that it can be automatically used with [unpkg](https://unpkg.com/). - -First, include the script in your HTML: - -```html -