Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reuse AuthToken in typescript-wallet-sdk #177

Open
Maras0830 opened this issue Nov 5, 2024 · 3 comments
Open

How to reuse AuthToken in typescript-wallet-sdk #177

Maras0830 opened this issue Nov 5, 2024 · 3 comments

Comments

@Maras0830
Copy link

What problem does your feature solve?

The current implementation of the @stellar/typescript-wallet-sdk lacks a straightforward method for reusing an AuthToken obtained from the SEP-10 authentication process. When attempting to invoke AuthToken.from(string) to deserialize a previously acquired token, developers encounter the following error:

Error: Cannot find module '@stellar/typescript-wallet-sdk/lib/walletSdk/Types'

And we also cannot directly use string of AuthToken across different SEP interactions, as the SDK performs type checks on the AuthToken parameter.

What would you like to see?

A resolution to the module resolution error associated with the AuthToken.from() method is desired. This would enable us to seamlessly deserialize JWT strings into AuthToken instances, reuse throughout the token's validity period.

What alternatives are there?

In the absence of a direct solution, I used resort to creating custom classes that mimic the structure of AuthToken. And then use type assertions, such as as unknown as AuthToken, to cast these custom instances to the desired type. While this approach can be functional, it is not ideal and may lead to maintenance challenges.

@Ifropc
Copy link
Contributor

Ifropc commented Nov 5, 2024

Normally, you should not need to convert string -> AuthToken, by authenticating directly with the anchor and then using AuthToken you get in return.
Is there any reason you want to construct AuthToken from string directly?
cc @CassioMG

@Maras0830
Copy link
Author

Maras0830 commented Nov 7, 2024

Hi @Ifropc , because I just use sep24() to get Transaction.
I know we can use Token in Anchor's request header.

Here is my code below:

return await sep24.getTransactionsForAsset({
  authToken,
  lang: 'en',
  assetCode: 'USDC',
})

The first parameter of this function requires the AuthToken type to be passed in, but when I only store string in my storage, and when I get it again, and use AuthToken.from(), the problem I mentioned above will arise.

@Ifropc
Copy link
Contributor

Ifropc commented Nov 7, 2024

Hmmm, how do you obtain token originally?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants