Skip to content
Draft
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: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Copy and paste the following code into a new file in your project:
// lib/ironOptions.ts

import { IronSessionOptions } from 'iron-session';
import { Address } from 'wagmi';

if (!process.env.IRON_SESSION_PASSWORD)
throw new Error('IRON_SESSION_PASSWORD must be set');
Expand All @@ -75,7 +76,7 @@ const ironOptions: IronSessionOptions = {

declare module "iron-session" {
interface IronSessionData {
address?: string | undefined;
address?: Address | undefined;
nonce?: string | undefined;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IncomingMessage, ServerResponse } from 'http';
import { generateNonce, SiweMessage } from 'siwe';
import { Address } from 'wagmi';
import { fromZodError } from 'zod-validation-error';
import { GetSessionResponse, signInRequestSchema, SignInResponse, SignOutResponse } from './types.js';

Expand Down Expand Up @@ -55,7 +56,7 @@ export const signIn: RequestHandler<SignInResponse> = async (req, res) => {
if (!success) return res.status(500).send("Unknown Error");

req.session.nonce = undefined;
req.session.address = data.address;
req.session.address = data.address as Address;
await req.session.save();

return res.send("OK");
Expand Down
7 changes: 4 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import "iron-session";
import { Address } from "wagmi";
import { z } from "zod";

declare module "iron-session" {
interface IronSessionData {
address?: string | undefined;
address?: Address | undefined;
nonce?: string | undefined;
}
}
Expand All @@ -30,8 +31,8 @@ export const signInRequestSchema = z.object({

export type GetSessionResponse = {
authenticated: boolean,
address?: string,
nonce?: string
address?: Address,
nonce?: string,
};

export type SignInRequest = z.infer<typeof signInRequestSchema>;
Expand Down