{"_id":"@airsoko/auth","_rev":"6-8d5c71d57ab99daf03fb744b48fba212","name":"@airsoko/auth","dist-tags":{"latest":"0.0.26"},"versions":{"0.0.1":{"name":"@airsoko/auth","version":"0.0.1","author":"","license":"UNLICENSED","_id":"@airsoko/auth@0.0.1","maintainers":[{"name":"cluewax","email":"cluewaxing@gmail.com"}],"dist":{"shasum":"14c61d2edca7536ecad45f77f7a6f17cfa866aa4","tarball":"https://registry.npmjs.org/@airsoko/auth/-/auth-0.0.1.tgz","fileCount":91,"integrity":"sha512-RbY1F9KpKKgLFtmr9A7GIrPE7XIqNhIdyAsMisuKTwGz2h9jK9OP9jgPSX2gNjZDlV0df02Dyq2+MDCJTN2Jrw==","signatures":[{"sig":"MEUCIFH8x5J7jLiWF1m0FNEaC55EViyHJkxVp3/CWlAQ1bKyAiEAy9kBvcpWZGvhDNXgE4dRClghboszMtaXtOXGOMgwIXM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":124956},"main":"./dist/src/index.js","types":"./dist/src/index.d.ts","gitHead":"5f0771ed004dd4b76492e3c50e950b48cd209418","private":false,"scripts":{"dev":"tsc --watch","test":"jest","build":"tsc --build","clean":"rimraf dist && rimraf .turbo && rimraf node_modules","format":"prettier --write \"src/**/*.ts\"","prebuild":"yarn clean","preLaunch":"tsc --build","test:watch":"jest --watch"},"_npmUser":{"name":"cluewax","email":"cluewaxing@gmail.com"},"_npmVersion":"9.8.1","directories":{},"_nodeVersion":"18.18.2","dependencies":{"js-cookie":"^3.0.5","@airsoko/api":"*","@airsoko/graphql":"*"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/js-cookie":"^3.0.6","@airsoko/tsconfig":"*"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.0.1_1709915667960_0.7350823921396348","host":"s3://npm-registry-packages"}},"0.0.2":{"name":"@airsoko/auth","version":"0.0.2","author":"","license":"UNLICENSED","_id":"@airsoko/auth@0.0.2","maintainers":[{"name":"cluewax","email":"cluewaxing@gmail.com"}],"dist":{"shasum":"dd03301f0f5e643dfe7491505a3462ec24d37130","tarball":"https://registry.npmjs.org/@airsoko/auth/-/auth-0.0.2.tgz","fileCount":92,"integrity":"sha512-ixIxHGXNeJ0j7aV0cqoScqvgAQM2cDw+A/6Gxy2m3w7tOy4OAdHG33gf/gEbbwJR1y5cq/0qjr4rKn9oeovSwg==","signatures":[{"sig":"MEYCIQDAvUxOqGwlLzoWYUzF9NJWHxRSMndWV2U3a5M1GBcZPwIhANY0FRDa4QdkEFaqMbTI4ocqsVZrdTJ0vk5lFaLNwj9c","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":131730},"main":"./dist/src/index.js","types":"./dist/src/index.d.ts","gitHead":"5f0771ed004dd4b76492e3c50e950b48cd209418","private":false,"scripts":{"dev":"tsc --watch","test":"jest","build":"tsc --build","clean":"rimraf dist && rimraf .turbo && rimraf node_modules","format":"prettier --write \"src/**/*.ts\"","prebuild":"yarn clean","preLaunch":"tsc --build","test:watch":"jest --watch"},"_npmUser":{"name":"cluewax","email":"cluewaxing@gmail.com"},"_npmVersion":"9.8.1","description":"<br/>","directories":{},"_nodeVersion":"18.18.2","dependencies":{"js-cookie":"^3.0.5","@airsoko/api":"*","@airsoko/graphql":"*"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/js-cookie":"^3.0.6","@airsoko/tsconfig":"*"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.0.2_1710052342189_0.11170576334545945","host":"s3://npm-registry-packages"}},"0.0.3":{"name":"@airsoko/auth","version":"0.0.3","author":"","license":"UNLICENSED","_id":"@airsoko/auth@0.0.3","maintainers":[{"name":"cluewax","email":"cluewaxing@gmail.com"}],"dist":{"shasum":"117f7aea5b2538e5cf9f50a415437bfbfe36ef49","tarball":"https://registry.npmjs.org/@airsoko/auth/-/auth-0.0.3.tgz","fileCount":92,"integrity":"sha512-2AbEXjUbc2SRwsvYG5Qci8VNoMsniLTjxwec+9kdsJ3MWu47nuH/LScLSZjQDZ8owBFQ71Piu82ZkcilMsPHDg==","signatures":[{"sig":"MEUCIDD3khwV8eKQEe8e0ARdgV7ikwKBhqTuWBrJSIZjvLgxAiEA4sYAfu0xErpSfnrasIsi1dtkJFqOv1CTkyYH6UBopmg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":131564},"main":"./dist/src/index.js","types":"./dist/src/index.d.ts","gitHead":"5f0771ed004dd4b76492e3c50e950b48cd209418","private":false,"scripts":{"dev":"tsc --watch","test":"jest","build":"tsc --build","clean":"rimraf dist && rimraf .turbo && rimraf node_modules","format":"prettier --write \"src/**/*.ts\"","prebuild":"yarn clean","preLaunch":"tsc --build","test:watch":"jest --watch"},"_npmUser":{"name":"cluewax","email":"cluewaxing@gmail.com"},"_npmVersion":"9.8.1","description":"## 📑 Table of Contents","directories":{},"_nodeVersion":"18.18.2","dependencies":{"js-cookie":"^3.0.5","@airsoko/api":"*","@airsoko/graphql":"*"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/js-cookie":"^3.0.6","@airsoko/tsconfig":"*"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.0.3_1710056385057_0.9295204861808508","host":"s3://npm-registry-packages"}},"0.0.4":{"name":"@airsoko/auth","version":"0.0.4","author":"","license":"UNLICENSED","_id":"@airsoko/auth@0.0.4","maintainers":[{"name":"cluewax","email":"cluewaxing@gmail.com"}],"dist":{"shasum":"c3d1cdbe4a4bd1f5546a12f1873966c52f5927ad","tarball":"https://registry.npmjs.org/@airsoko/auth/-/auth-0.0.4.tgz","fileCount":92,"integrity":"sha512-8Sq1jJxr0QaDO9n6xUSTuxs2Ji884i0t4UrjGo3S9ka/+0PrrduZ01SeDsODgtrXoz7BhxL8foLW2cSsFBtgiw==","signatures":[{"sig":"MEUCIQDhVs0gC5hdZZfgdHd8CuQ1X4kEq+udn6LAHyBuTxEdvAIgNNfpgQalD21/sYxh5pYYDnQCndS5dAwQB0G2TrP0ojs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":131547},"main":"./dist/src/index.js","types":"./dist/src/index.d.ts","gitHead":"da3bbd622ec16219e41974dcdd3c22ae5dd276b1","private":false,"scripts":{"dev":"tsc --watch","test":"jest","build":"tsc --build","clean":"rimraf dist && rimraf .turbo && rimraf node_modules","format":"prettier --write \"src/**/*.ts\"","prebuild":"yarn clean","preLaunch":"tsc --build","test:watch":"jest --watch"},"_npmUser":{"name":"cluewax","email":"cluewaxing@gmail.com"},"_npmVersion":"9.8.1","description":"## 📑 Table of Contents","directories":{},"_nodeVersion":"18.18.2","dependencies":{"js-cookie":"^3.0.5","@airsoko/api":"*","@airsoko/graphql":"*"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/js-cookie":"^3.0.6","@airsoko/tsconfig":"*"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.0.4_1716452467634_0.32131491013221236","host":"s3://npm-registry-packages"}},"0.0.5":{"name":"@airsoko/auth","version":"0.0.5","author":"","license":"UNLICENSED","_id":"@airsoko/auth@0.0.5","maintainers":[{"name":"cluewax","email":"cluewaxing@gmail.com"}],"dist":{"shasum":"f27a6c916ad5f0a2b8ad116240739f658c8fda20","tarball":"https://registry.npmjs.org/@airsoko/auth/-/auth-0.0.5.tgz","fileCount":92,"integrity":"sha512-uIUugriw+f8Fi2HzzuyifHORc12I2LHZEfcZ5r1EtlehCQyxaUmfSk5NUz9p1LBGJ+J5ZtwCfGumfsVGGiwsdw==","signatures":[{"sig":"MEUCIFN582I7S7pF0Y8tDmSG1RTDt1yn66i2RN5/bQPQ6PvbAiEAsNgIENEBs1rrf9vAw8p+nNDSf+AUfX1LAllrXOF7DVY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":131985},"main":"./dist/src/index.js","types":"./dist/src/index.d.ts","gitHead":"8fba08d6015984cae9c5c3f44736623e44d7b7dd","private":false,"scripts":{"dev":"tsc --watch","test":"jest","build":"tsc --build","clean":"rimraf dist && rimraf .turbo && rimraf node_modules","format":"prettier --write \"src/**/*.ts\"","prebuild":"yarn clean","preLaunch":"tsc --build","test:watch":"jest --watch"},"_npmUser":{"name":"cluewax","email":"cluewaxing@gmail.com"},"_npmVersion":"11.0.0","description":"## 📑 Table of Contents","directories":{},"_nodeVersion":"18.20.3","dependencies":{"js-cookie":"^3.0.5","@airsoko/api":"*","@airsoko/graphql":"*"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/js-cookie":"^3.0.6","@airsoko/tsconfig":"*"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.0.5_1760813883140_0.0682440843461527","host":"s3://npm-registry-packages-npm-production"}},"0.0.26":{"name":"@airsoko/auth","version":"0.0.26","description":"## 📑 Table of Contents","author":"","private":false,"license":"UNLICENSED","main":"./dist/src/index.js","types":"./dist/src/index.d.ts","scripts":{"prebuild":"yarn clean","build":"tsc --build","format":"prettier --write \"src/**/*.ts\"","dev":"tsc --watch","clean":"rimraf dist && rimraf .turbo && rimraf node_modules","preLaunch":"tsc --build","test":"jest","test:watch":"jest --watch"},"dependencies":{"@airsoko/api":"*","@airsoko/graphql":"*","js-cookie":"^3.0.5"},"devDependencies":{"@airsoko/tsconfig":"*","@types/js-cookie":"^3.0.6"},"publishConfig":{"access":"public"},"_id":"@airsoko/auth@0.0.26","gitHead":"306c46921f4f762771e1a2fa087c58f451e9971a","_nodeVersion":"18.20.3","_npmVersion":"11.0.0","dist":{"integrity":"sha512-81U7sIDiZIw6vy6ypbzny7OmRfbFKHXaLD3O8dy2od3U/sTR3ByIX+chO5tjo/+6QgxzLEeK2o17o3ugLzbU4g==","shasum":"e645ed96d3f83e79efe62bc1c79a01f644da2161","tarball":"https://registry.npmjs.org/@airsoko/auth/-/auth-0.0.26.tgz","fileCount":92,"unpackedSize":131985,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIAUdf+cfYgbx62drszfmDg+nJjqiRqCZFIqEUHqFwuylAiBETlJ2Y6tap+wsV77AjBzVs8tkcrp5BY0ZwjGvne1oOg=="}]},"_npmUser":{"name":"cluewax","email":"cluewaxing@gmail.com"},"directories":{},"maintainers":[{"name":"cluewax","email":"cluewaxing@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/auth_0.0.26_1775389474573_0.9120743134699114"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-08T16:34:27.869Z","modified":"2026-04-05T11:44:34.836Z","0.0.1":"2024-03-08T16:34:28.173Z","0.0.2":"2024-03-10T06:32:22.357Z","0.0.3":"2024-03-10T07:39:45.226Z","0.0.4":"2024-05-23T08:21:07.777Z","0.0.5":"2025-10-18T18:58:03.443Z","0.0.26":"2026-04-05T11:44:34.705Z"},"license":"UNLICENSED","description":"## 📑 Table of Contents","maintainers":[{"name":"cluewax","email":"cluewaxing@gmail.com"}],"readme":"# Airsoko auth package\n\n## 📑 Table of Contents\n\n<details>\n<summary>Table</summary>\n\n- [Overview](#overview)\n- [Installation ](#installation)\n  - [Prerequisites](#prerequisites)\n  - [Installation](#global-installation)\n  - [Using Airsoko ](#Project-Installation)\n  - [Updating](#updating)\n  - [Uninstallation](#uninstalling)\n- [API Reference](#api-reference)\n- [License](#license)\n- [Built With](#built-with)\n\n    </details>\n\n## Overview\n\nThe npm package provides essential utilities for handling authentication within the Airsoko application.\n\n## Installation\n\n```bash\nnpm install @airsoko/auth\n```\n\n### Prerequisites\n\n- Node.js (version 16 or higher)\n- npm (or yarn)\n\n### Uninstalling\n\nIf you wish to uninstall Airsoko next, use:\n\n```sh\nnpm uninstall  @airsoko/auth\n```\n\n### API Reference\n\n## Example\n\n### Step 1: Wrap the Application with `AuthProvider`\n\nTo enable authentication within your React application, you need to wrap it with the `AuthProvider` component provided by the Macive Auth package. This component sets up the necessary authentication context, allowing your components to access authentication-related information.\n\nHere's an example of how to use the `AuthProvider`:\n\n```typescript\nimport { AuthProvider } from \"@airsoko/auth;\n\n<AuthProvider\n  domain='my-shop.airsoko.com'\n  clientId=\"YOUR_AUTH_CLIENT_ID\"\n  redirectUri='https://my-shop.airsoko.com'\n  audience=\"CUSTOMER\"\n>\n  {/* Your application components */}\n</AuthProvider>\n```\n\nParameters:\n\n- domain: The Airsoko domain associated with your application. .\n\n- clientId: Your Airsoko client ID. Replace \"YOUR_AUTH0_CLIENT_ID\" with the actual client ID for your application.\n\n- redirectUri: The URI to which the user will be redirected after authentication. It is usually set to the application's domain or https://my-shop.airsoko.com/my-auth-dwstination'.\n\n- audience: The audience parameter for Auth0, typically representing the target audience for authentication. In this example, it is set to \"CUSTOMER\".\n\n### Step 2: Authentication Hook use with `useAuth`\n\nThe useAuth hook provides a convenient way to integrate authentication functionalities into your React application. This hook allows you to access user information, check authentication status, and perform actions based on the authentication state.\n\n### Usage Example: Private Route Component\n\nHere's an example of how you can use the useAuth hook to create a private route component using Next.js:\n\n```typescript\nimport { useAuth } from \"@airsoko/auth\";\nimport Link from \"next/link\";\nimport React from \"react\";\n\ntype AuthPropsType = {\n  permissions?: string[];\n};\n\ninterface PrivateRouteProps {\n  authProps: AuthPropsType;\n  children: React.ReactNode;\n}\n\nconst PrivateRoute: React.FC<PrivateRouteProps> = ({ children, authProps }) => {\n  const { user, goLogin, sessionLoading, isAuthenticated } = useAuth();\n  const isUser = user?.id;\n\n  React.useEffect(() => {\n    if (!sessionLoading) {\n      if (!isAuthenticated) {\n        if (!isUser) goLogin();\n      } else {\n        // Additional logic for authenticated users, if needed.\n      }\n    }\n  }, [isUser, sessionLoading]);\n\n  // If the user is authenticated and has the required permissions.\n  // Replace with your own permission checking logic if needed.\n  if (isUser) {\n    // Render the protected content.\n    return <>{children}</>;\n  }\n\n  // Session is being fetched, or no user.\n  // If no user, useEffect() will redirect to the login page.\n  return <GlobalLoader />;\n};\n\n```\n\n## Functions\n\n### 1. `goLogin` Function - Redirect to Login\n\nThe goLogin function is designed to redirect users to the login page. This function can be useful in scenarios where you want to ensure users are authenticated before accessing certain parts of your application.\n\n```typescript\nimport { useAuth } from \"@airsoko/auth\";\n\nconst YourComponent: React.FC = () => {\n  const { goLogin } = useAuth();\n\n  const handleLoginButtonClick = () => {\n    goLogin();\n  };\n\n  return (\n    <div>\n      <p>Welcome to your application!</p>\n      <button onClick={handleLoginButtonClick}>Login</button>\n    </div>\n  );\n};\n\n```\n\n### 2. `signIn` Function - Sign In and Redirect\n\nThe `signIn` function is designed to sign in the user to the application using a provided token and redirect them to a specific destination. This function is useful when you want to handle custom authentication logic and redirect users after successful sign-in.\n\n```typescript\nimport { useAuth } from \"@airsoko/auth\";\n\nconst YourComponent: React.FC = () => {\n  const { signIn } = useAuth();\n\n  const handleSignInButtonClick = async () => {\n    try {\n      // Perform your authentication logic to obtain a token.\n      const authToken = \"YOUR_OBTAINED_TOKEN\";\n\n      // Use the signIn function to sign in the user and redirect.\n      await signIn(authToken);\n\n      // After successful sign-in, the user will be redirected.\n    } catch (error) {\n      console.error(\"Authentication failed:\", error);\n      // Handle authentication failure.\n    }\n  };\n\n  return (\n    <div>\n      <p>Welcome to your application!</p>\n      <button onClick={handleSignInButtonClick}>Sign In</button>\n    </div>\n  );\n};\n\n```\n\n### 3. `logout` Function - Log Out User\n\nThe logout function is designed to log out the user from the application. This function can be used to initiate the logout process, which may include clearing session data and redirecting the user to a specified destination.\n\n```typescript\nimport { useAuth } from \"@airsoko/auth\";\n\nconst YourComponent: React.FC = () => {\n  const { logout } = useAuth();\n\n  const handleLogoutButtonClick = async () => {\n    try {\n      // Use the logout function to log out the user.\n      await logout();\n\n      // After successful logout, you can perform additional actions or redirect the user.\n      console.log(\"User successfully logged out.\");\n    } catch (error) {\n      console.error(\"Logout failed:\", error);\n      // Handle logout failure.\n    }\n  };\n\n  return (\n    <div>\n      <p>Welcome to your application!</p>\n      <button onClick={handleLogoutButtonClick}>Logout</button>\n    </div>\n  );\n};\n\n```\n\n## 🤝 Contributing\n\nContributions to improve this package are welcome. Please adhere to the project's coding standards and commit guidelines.\n\n## License\n\nMIT License\n\n## ⚒️ Built With\n\n- ![@types/node](https://img.shields.io/badge/@types/node-40A2D8?style=for-the-badge&logo=%40types%2Fnode&logoColor=white)\n- ![typescript](https://img.shields.io/badge/typescript-40A2D8?style=for-the-badge&logo=typescript&logoColor=white)\n\n  ***\n\n  _🌟 This README was generated with 💖 by [Airsoko](https://github.com/airsoko)_\n","readmeFilename":"README.md"}