-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for custom auth server (#145)
* add support for login with custom auth endpoint * error if using custom auth in react package * add changesets * refactor wanderers user fetching
- Loading branch information
1 parent
b82e78b
commit 4f2c50f
Showing
9 changed files
with
182 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@treasure-dev/tdk-react": patch | ||
--- | ||
|
||
Updated to handle attempts to log in with custom auth endpoint |
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,5 @@ | ||
--- | ||
"@treasure-dev/tdk-core": patch | ||
--- | ||
|
||
Added support for login with custom auth endpoint |
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,35 @@ | ||
import type { LoginCustomReply } from "../schema"; | ||
|
||
const WANDERERS_API_URL = "https://id.wanderers.ai/sessions/whoami"; | ||
|
||
type WanderersSession = { | ||
active: boolean; | ||
expires_at: string; | ||
identity: { | ||
id: string; | ||
traits: { | ||
email: string; | ||
}; | ||
}; | ||
}; | ||
|
||
export const validateWanderersUser = async ( | ||
cookie?: string, | ||
token?: string, | ||
): Promise<LoginCustomReply | undefined> => { | ||
const response = await fetch(WANDERERS_API_URL, { | ||
headers: cookie ? { Cookie: cookie } : { "X-Session-Token": token ?? "" }, | ||
}); | ||
|
||
const session: WanderersSession = await response.json(); | ||
const expiresAt = new Date(session.expires_at).getTime(); | ||
if (!session.active || expiresAt < Date.now()) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
userId: session.identity.id, | ||
email: session.identity.traits.email, | ||
exp: Math.floor(expiresAt / 1000), | ||
}; | ||
}; |
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