-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flav/augment get server side props (#4140)
* Add `withGetServerSidePropsRequirements` wrapper * 👕 * ✨ * ✂️ * 👕 * Address comments from review * Tmp * Augment getServerSideProps with session * ✨ * ✨ * ✂️ * 🔙 * 👕
- Loading branch information
Showing
60 changed files
with
530 additions
and
515 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { UserProviderType } from "@dust-tt/types"; | ||
|
||
interface LegacyProvider { | ||
provider: UserProviderType; | ||
id: number | string; | ||
} | ||
|
||
interface LegacyExternalUser { | ||
name: string; | ||
email: string; | ||
image?: string; | ||
username?: string; | ||
email_verified?: boolean; | ||
} | ||
|
||
interface LegacySession { | ||
provider: LegacyProvider; | ||
user: LegacyExternalUser; | ||
} | ||
|
||
function isLegacyExternalUser(user: unknown): user is LegacyExternalUser { | ||
return ( | ||
typeof user === "object" && | ||
user !== null && | ||
"email" in user && | ||
"name" in user | ||
); | ||
} | ||
|
||
function isLegacyProvider(provider: unknown): provider is LegacyProvider { | ||
return ( | ||
typeof provider === "object" && | ||
provider !== null && | ||
"provider" in provider && | ||
"id" in provider | ||
); | ||
} | ||
|
||
export function isLegacySession(session: unknown): session is LegacySession { | ||
return ( | ||
typeof session === "object" && | ||
session !== null && | ||
"provider" in session && | ||
isLegacyProvider(session.provider) && | ||
"user" in session && | ||
isLegacyExternalUser(session.user) | ||
); | ||
} | ||
|
||
// We only expose generic types to ease phasing out. | ||
|
||
export type Session = LegacySession; | ||
|
||
export function isValidSession(session: unknown): session is Session { | ||
return isLegacySession(session); | ||
} |
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
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
Oops, something went wrong.