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

superTokensInstance should not be package-level #420

Open
Leskodamus opened this issue Jul 11, 2024 · 1 comment
Open

superTokensInstance should not be package-level #420

Leskodamus opened this issue Jul 11, 2024 · 1 comment

Comments

@Leskodamus
Copy link

Leskodamus commented Jul 11, 2024

The current implementation defines and uses a package-level variable for the *superTokens instance
which is not a great if anyone would like to have multiple instances or for testing (in parallel).

Instead it should be handled in encapsulation, for example by changing the func supertokensInit(config TypeInput) error {} and func Init(config TypeInput) error {} functions to return a *superTokens object and by making type superTokens struct {} a public struct:

type SuperTokens struct {}

func supertokensInit(config TypeInput) (error, *SuperTokens) {}

func Init(config TypeInput) (error, *SuperTokens) {}

Maybe Init(config TypeInput) should even be renamed to NewSuperTokens or NewSuperTokensInstnace.

To me this implementation is not very idiomatic Go and looks more like JavaScript.
This would probably a bigger change affecting various parts of the SDK.

Edit: After using the SDK a bit more, I've realized that almost every type has a singleton instance. This is not very flexible and definitely not a good design pattern. Basically all singletons should be removed and refactored with more structure in mind.

@rishabhpoddar
Copy link
Contributor

rishabhpoddar commented Jul 11, 2024

Agreed. Until this is done though, you can call the supertokens.ResetForTest() function during tests so that you can call init multiple times.

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