-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify profile auth & signature flow (#2012)
* Remove JWT logic from api * add tests * use validateSignature in handlers * npm version major * use wallet regex * cleanup put schema and add tests * add FirestoreUserDoc schema and add more tests * merge firebase tools and cleanup * fix: undefined nonce * remove session plugin * fix type definitions * abstract authenticateProfile prehandler * Add fallback for SIGN_PROFILE_MESSAGE * push test debug * resolve conflicts & rebase staging * fix import * pass tests and remove debug * add better fallback * generate:types * correct status code in authenticate middleware * add debug statements * push more debug * remove debug and change log * fix: empty strings instead of undefined * fix tests
- Loading branch information
1 parent
506014c
commit 62f4b34
Showing
41 changed files
with
860 additions
and
774 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import "fastify"; | ||
import { UserProfile } from "./models/UserProfile.model"; | ||
import { ILcacheStorage } from "./plugins/caching"; | ||
|
||
declare module "fastify" { | ||
interface FastifyRequest { | ||
/** Authenticated routes may pass the userDoc down from preHandler */ | ||
userProfile?: UserProfile | null; | ||
} | ||
interface FastifyInstance { | ||
lcache: ILcacheStorage; | ||
} | ||
interface FastifyInstance { | ||
firebase: FirebaseInstance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
import { Static, Type } from "@sinclair/typebox"; | ||
import { Nullable } from "./Utility.model"; | ||
|
||
//This model matches the document structure in https://console.firebase.google.com/project/klimadao-staging | ||
/** | ||
* This model matches the document structure in https://console.firebase.google.com/project/klimadao-staging | ||
* Should not be documented in public docs. | ||
* At time of writing we only use this for types, we don't validate firestore writes against this schema. | ||
* | ||
* Updated 09.12.2023 - added nonce | ||
*/ | ||
|
||
export const UserProfileModel = Type.Object({ | ||
handle: Nullable(Type.String()), | ||
username: Type.String(), | ||
description: Nullable(Type.String()), | ||
profileImgUrl: Nullable(Type.String()), | ||
updatedAt: Type.Number(), | ||
/** Unique, immutable, case-insensitive handle */ | ||
handle: Type.String({ minLength: 3, maxLength: 24 }), | ||
/** Unix timestamp ms */ | ||
createdAt: Type.Number(), | ||
/** Unix timestamp ms */ | ||
updatedAt: Type.Number(), | ||
/** Lower case wallet address which owns the profile */ | ||
address: Type.String(), | ||
/** Editable username */ | ||
username: Type.String({ minLength: 2 }), | ||
/** Optional profile description. May also be empty string. */ | ||
description: Type.Optional(Type.String()), | ||
/** Optional image url. May also be empty string. */ | ||
profileImgUrl: Type.Optional(Type.String()), | ||
/** | ||
* Nonce, incremented once per edit, may not be present | ||
* Ensures the same message hash can never be reused (replay attack) | ||
* */ | ||
nonce: Type.Optional(Type.Number()), | ||
}); | ||
|
||
export type UserProfile = Static<typeof UserProfileModel>; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.