@@ -57,7 +57,7 @@ npm install @randombits/use-siwe wagmi ethers iron-session
5757
5858Copy and paste the following code into a new file in your project:
5959
60- ```
60+ ``` ts
6161// lib/ironOptions.ts
6262
6363import { IronSessionOptions } from ' iron-session' ;
@@ -106,7 +106,7 @@ https://github.com/vvo/iron-session#typing-session-data-with-typescript
106106
107107Copy and past the following code into ` pages/api/auth/[[...route]].ts ` :
108108
109- ```
109+ ``` ts
110110import { withIronSessionApiRoute } from " iron-session/next" ;
111111import ironOptions from " lib/ironOptions" ;
112112import { siweApi } from " @randombits/use-siwe/next"
@@ -118,7 +118,7 @@ export default withIronSessionApiRoute(siweApi(), ironOptions);
118118
119119To add auth routes to your existing express API, add the following:
120120
121- ```
121+ ``` ts
122122import express from " express" ;
123123import { ironSession } from " iron-session/express" ;
124124import ironOptions from " ./ironOptions.js" ;
@@ -135,7 +135,6 @@ app.use(ironSession(ironOptions));
135135app .use (' /auth' , authRouter ());
136136
137137app .listen (3001 );
138-
139138```
140139
141140## Wrapping your application with ` SiweProvider `
@@ -144,7 +143,7 @@ Any component that uses the any of the UseSIWE hooks must be wrapped with the
144143` SiweProvider ` component. For a Next.js application we recommend doing so in
145144` pages/_app.tsx ` like in the example below:
146145
147- ```
146+ ``` ts
148147// pages/_app.tsx
149148
150149import type { AppProps } from ' next/app' ;
@@ -185,7 +184,7 @@ export default function MyApp({ Component, pageProps }: AppProps) {
185184Check to see is a user is authenticated with the ` useSession ` hook like in the
186185example below:
187186
188- ```
187+ ``` ts
189188import { useSession } from " @randombits/use-siwe" ;
190189
191190export const AuthCheck = () => {
@@ -204,7 +203,7 @@ to see if `req.session.address` is set. If a user is authenticated,
204203` req.session.address ` will be set to their address, otherwise it will be
205204` undefined ` .
206205
207- ```
206+ ``` ts
208207import ironOptions from ' @/lib/ironOptions'
209208import { withIronSessionApiRoute } from ' iron-session/next/dist'
210209import type { NextApiHandler } from ' next'
@@ -222,7 +221,7 @@ export default withIronSessionApiRoute(handler, ironOptions);
222221Login the user by calling the ` signIn ` function returned by the ` useSignIn `
223222hook:
224223
225- ```
224+ ``` ts
226225import { useSignIn } from " @randombits/use-siwe" ;
227226
228227const SignInButton = () => {
@@ -236,7 +235,7 @@ const SignInButton = () => {
236235Logout the user by calling the ` signOut ` function returned by the ` useSignOut `
237236hook:
238237
239- ```
238+ ``` ts
240239import { useSignOut } from " @randombits/use-siwe" ;
241240
242241const SignOutButton = () => {
@@ -256,7 +255,7 @@ setting:
256255
257256#### Usage
258257
259- ```
258+ ``` ts
260259const options: UseSiweOptions = {
261260 baseUrl: " /v2/api/auth" ,
262261};
@@ -276,7 +275,7 @@ Context provider component that must wrap all components that use `useSession`,
276275
277276#### Usage
278277
279- ```
278+ ``` ts
280279import type { AppProps } from ' next/app' ;
281280import { SiweProvider } from ' @randombits/use-siwe' ;
282281
@@ -299,7 +298,7 @@ A hook that returns the the current state of the users session.
299298
300299#### Usage
301300
302- ```
301+ ```ts
303302import { useSession } from "@randombits/use-siwe";
304303
305304export const Component = () => {
@@ -316,7 +315,7 @@ export const Component = () => {
316315Returns a ` UseQueryResult ` ([ref](https://tanstack.com/query/latest/docs/react/reference/useQuery))
317316augmented with the following:
318317
319- ```
318+ ` ` ` ts
320319{
321320 authenticated : boolean ;
322321 address ?: string ;
@@ -331,7 +330,7 @@ as the status of that signIn process.
331330
332331#### Usage
333332
334- ```
333+ ` ` ` ts
335334import { useSignIn } from " @randombits/use-siwe" ;
336335
337336const SignInButton = () => {
@@ -342,7 +341,7 @@ const SignInButton = () => {
342341
343342#### Options
344343
345- ```
344+ ` ` ` ts
346345{
347346 onSuccess : () => void ,
348347 onError : () => void ,
@@ -354,7 +353,7 @@ const SignInButton = () => {
354353Returns a ` UseMutationResult ` ([ref](https://tanstack.com/query/latest/docs/react/reference/useMutation))
355354augmented with the following:
356355
357- ```
356+ ` ` ` ts
358357{
359358 signIn : () => void ,
360359 SignInAsync : () => Promise < void > ,
@@ -368,7 +367,7 @@ current user and disconnect their wallet.
368367
369368#### Usage
370369
371- ```
370+ ` ` ` ts
372371import { useSignOut } from " @randombits/use-siwe" ;
373372
374373const SignOutButton = () => {
@@ -379,7 +378,7 @@ const SignOutButton = () => {
379378
380379#### Options
381380
382- ```
381+ ` ` ` ts
383382{
384383 onSuccess : () => void ,
385384 onError : () => void ,
@@ -391,7 +390,7 @@ const SignOutButton = () => {
391390Returns a ` UseMutationResult ` ([ref](https://tanstack.com/query/latest/docs/react/reference/useMutation))
392391augmented with the following:
393392
394- ```
393+ ` ` ` ts
395394{
396395 signOut : () => void ,
397396 SignOutAsync : () => Promise < void > ,
@@ -405,7 +404,7 @@ A hook that simply returns the options that have been set by in the
405404
406405#### Usage
407406
408- ```
407+ ` ` ` ts
409408import { useOptions , verify } from " @randombits/use-siwe" ;
410409
411410const verifyButton = (props ) => {
@@ -421,7 +420,7 @@ const verifyButton = (props) => {
421420
422421#### Return Value
423422
424- ```
423+ ` ` ` ts
425424useSiweOptions
426425` ` `
427426
@@ -434,7 +433,7 @@ routes.
434433
435434#### Usage
436435
437- ```
436+ ` ` ` ts
438437import { withIronSessionApiRoute } from " iron-session/next" ;
439438import ironOptions from " lib/ironOptions" ;
440439import { siweApi } from " @randombits/use-siwe/next"
@@ -444,7 +443,7 @@ export default withIronSessionApiRoute(siweApi(), ironOptions);
444443
445444#### Return Value
446445
447- ```
446+ ` ` ` ts
448447NextApiHandler
449448` ` `
450449
@@ -455,7 +454,7 @@ routes.
455454
456455#### Usage
457456
458- ```
457+ ` ` ` ts
459458import express from " express" ;
460459import { ironSession } from " iron-session/express" ;
461460import ironOptions from " ./ironOptions.js" ;
@@ -471,7 +470,7 @@ app.listen(3001);
471470
472471#### Return Value
473472
474- ```
473+ ` ` ` ts
475474Router
476475` ` `
477476
@@ -483,7 +482,7 @@ A function to retrieve the session data where using a hook doesn't make sense.
483482
484483#### Usage
485484
486- ```
485+ ` ` ` ts
487486import { getSession } from " @randombits/use-siwe" ;
488487
489488const addressOrNull = async () => {
@@ -499,7 +498,7 @@ const addressOrNull = async () => {
499498
500499#### Return Value
501500
502- ```
501+ ` ` ` ts
503502{
504503 authenticated : boolean ;
505504 address ?: string ;
@@ -513,7 +512,7 @@ Returns a `SiweMessage` for the given address, chainId, and nonce.
513512
514513#### Usage
515514
516- ```
515+ ` ` ` ts
517516import { createMessage , getMessageBody } from " @randombits/use-siwe" ;
518517
519518const debugMessage = (address , chainId , nonce ) => {
@@ -527,7 +526,7 @@ const debugMessage = (address, chainId, nonce) => {
527526
528527- ` args : MessageArgs `
529528
530- ```
529+ ` ` ` ts
531530type MessageArgs = {
532531 address: string ,
533532 chainId: number ,
@@ -537,7 +536,7 @@ type MessageArgs = {
537536
538537#### Return Value
539538
540- ```
539+ ` ` ` ts
541540SiweMessage
542541` ` `
543542
@@ -548,7 +547,7 @@ SiweMessage object.
548547
549548#### Usage
550549
551- ```
550+ ` ` ` ts
552551import { createMessage , getMessageBody } from " @randombits/use-siwe" ;
553552
554553const debugMessage = (address , chainId , nonce ) => {
@@ -564,7 +563,7 @@ const debugMessage = (address, chainId, nonce) => {
564563
565564#### Return Value
566565
567- ```
566+ ` ` ` ts
568567string
569568` ` `
570569
@@ -575,7 +574,7 @@ the auth API. A successful verification will create a session for the user.
575574
576575#### Usage
577576
578- ```
577+ ` ` ` ts
579578import { verify } from " @randombits/use-siwe" ;
580579
581580const verifyButton = (props ) => {
@@ -598,7 +597,7 @@ const verifyButton = (props) => {
598597- ` args : VerifyArgs `
599598- ` options ?: UseSiweOptions `
600599
601- ```
600+ ` ` ` ts
602601type VerifyArgs = {
603602 message: SiweMessage ,
604603 signature: string ,
@@ -607,7 +606,7 @@ type VerifyArgs = {
607606
608607#### Return Value
609608
610- ```
609+ ` ` ` ts
611610boolean
612611` ` `
613612
@@ -617,7 +616,7 @@ A function to sign out the user where using a hook doesn't make sense.
617616
618617#### Usage
619618
620- ```
619+ ` ` ` ts
621620import { signOut } from " @randombits/use-siwe" ;
622621
623622// Logout a user after 1 hour
@@ -633,6 +632,6 @@ setTimeout(async () => {
633632
634633#### Return Value
635634
636- ```
635+ ` ` ` ts
637636Promise < void >
638637` ` `
0 commit comments