Initialization
To use the SAuthBase SDK, you must call the init()
method once somewhere in your application to initialize it.
Initialization requires specifying a secretKey
(a 64-character hexadecimal string used for authentication) and a redirect_url
to redirect to after authentication is complete.
Basic Initialization
src/index.ts
import { } from "sauthbase";
const = .({
: "your_64char_hex_secret_here",
: "http://localhost:3000/auth"
});
After initialization, you can access the same instance from anywhere using sauthbase.use()
:
src/index.ts
const = .();
const = .();
Notes
⚠️
Only call init()
once within your application. Subsequent calls will be ignored.
- Calling
use()
beforeinit()
will result in an error. - To check whether initialization has been completed, use
sauthbase.isReady()
:
src/index.ts
if (!.()) {
.({
: ..!,
: ..!
});
}
Common Errors
Situation | Error Message | Solution |
---|---|---|
use() called before init() | SAuthBase has not been initialized. | Run init() first |
secretKey is too short/undefined | Warning appears in console | Use a 64-character hexadecimal string |
init() called multiple times | Only the first call takes effect | This is normal behavior (no side effects) |
You’ve now completed the initialization of the SAuthBase SDK.
Last updated on