Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@oxyhq/services

Package Overview
Dependencies
Maintainers
0
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oxyhq/services

The Oxy Services Module is a comprehensive package designed to provide reusable services and components for building front-end applications with Oxy. It includes hooks and components for session management, user handling, and more, making it easier to int

  • 0.0.69
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
614
increased by2092.86%
Maintainers
0
Weekly downloads
 
Created
Source

Oxy Services Module 🚀

The Oxy Services Module is a comprehensive package designed to provide reusable services and components for building front-end applications with Oxy. It includes hooks and components for session management, user handling, and more, making it easier to integrate Oxy-based functionalities into your React applications.

Features ✨

  • Session Management: Easily manage user sessions with hooks like useOxySession.
  • User Handling: Fetch and display user information using functions like getUserById.
  • Components: Ready-to-use components such as SignInButton, AccountSwitcherModal, and SessionOwnerButton.

Usage Instructions

To use the OxyServicesModule, follow these steps:

  1. Install the package:

    npm install @oxyhq/services
    
  2. Import the necessary components and hooks in your project:

    import { useOxySession, getUserById, SignInButton, AccountSwitcherModal, SessionOwnerButton } from '@oxyhq/services';
    
  3. Use the components and hooks in your application. For example, to use the SignInButton component:

    import React from 'react';
    import { SignInButton } from '@oxyhq/services';
    
    const App = () => {
      return (
        <div>
          <SignInButton />
        </div>
      );
    };
    
    export default App;
    

Examples

Example 1: Using useOxySession Hook

The useOxySession hook fetches session data and provides error handling and status management.

import React from 'react';
import { useOxySession } from '@oxyhq/services';

const SessionComponent = () => {
  const { session, status, error } = useOxySession();

  if (status === 'loading') {
    return <div>Loading...</div>;
  }

  if (status === 'error') {
    return <div>Error: {error}</div>;
  }

  return (
    <div>
      <h1>Welcome, {session.user.name}!</h1>
      <p>Email: {session.user.email}</p>
    </div>
  );
};

export default SessionComponent;

Example 2: Using getUserById Function

The getUserById function fetches user data by ID and handles possible errors.

import React, { useEffect, useState } from 'react';
import { getUserById } from '@oxyhq/services';

const UserComponent = ({ userId }) => {
  const [user, setUser] = useState(null);
  const [error, setError] = useState(null);

  useEffect(() => {
    const fetchUser = async () => {
      try {
        const fetchedUser = await getUserById(userId);
        setUser(fetchedUser);
      } catch (err) {
        setError(err.message);
      }
    };

    fetchUser();
  }, [userId]);

  if (error) {
    return <div>Error: {error}</div>;
  }

  if (!user) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      <h1>{user.name}</h1>
      <p>Email: {user.email}</p>
    </div>
  );
};

export default UserComponent;

FAQs

Package last updated on 16 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc