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

@peable/services

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@peable/services - npm Package Compare versions

Comparing version 0.0.66 to 0.0.67

dist/AuthProvider.d.ts

26

dist/hooks/AuthService.d.ts

@@ -1,16 +0,14 @@

declare class AuthService {
private static instance;
private apiUrl;
private constructor();
static getInstance(): AuthService;
authenticate(token: string): Promise<boolean>;
generateToken(): Promise<string>;
signIn(credentials: {
username: string;
password: string;
}): Promise<string>;
logout(token: string): Promise<void>;
import React from "react";
import { ReactNode } from "react";
interface AuthContextProps {
user: any;
login: () => void;
logout: () => void;
isAuthenticated: boolean;
}
declare const _default: AuthService;
export default _default;
export declare const AuthProvider: ({ children }: {
children: ReactNode;
}) => React.JSX.Element;
export declare const useAuth: () => AuthContextProps;
export {};
//# sourceMappingURL=AuthService.d.ts.map

@@ -0,36 +1,43 @@

import React from "react";
import { createContext, useContext, useState, useEffect, } from "react";
import axios from "axios";
class AuthService {
static instance;
apiUrl = "https://auth.oxy.so/api/auth";
constructor() { }
static getInstance() {
if (!AuthService.instance) {
AuthService.instance = new AuthService();
const AuthContext = createContext(undefined);
export const AuthProvider = ({ children }) => {
const [user, setUser] = useState(null);
const [isAuthenticated, setIsAuthenticated] = useState(false);
useEffect(() => {
// Check if user session exists on mount
const token = localStorage.getItem("authToken");
if (token) {
authenticateToken(token);
}
return AuthService.instance;
}
async authenticate(token) {
}, []);
const authenticateToken = async (token) => {
try {
const response = await axios.post(`${this.apiUrl}/authenticate`, {
token,
});
return response.data.authenticated;
const response = await axios.post("https://auth.oxy.so/api/auth/validate", { token });
setUser(response.data.user);
setIsAuthenticated(true);
}
catch (error) {
console.error("Authentication failed:", error);
return false;
setIsAuthenticated(false);
}
};
const login = () => {
const redirectUrl = `${window.location.origin}/auth/callback`;
window.location.href = `https://auth.oxy.so/api/auth/login?redirectUrl=${redirectUrl}`;
};
const logout = () => {
localStorage.removeItem("authToken");
setUser(null);
setIsAuthenticated(false);
window.location.href = `https://auth.oxy.so/api/auth/logout?redirectUrl=${window.location.origin}`;
};
return (React.createElement(AuthContext.Provider, { value: { user, login, logout, isAuthenticated } }, children));
};
export const useAuth = () => {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error("useAuth must be used within an AuthProvider");
}
async generateToken() {
const response = await axios.get(`${this.apiUrl}/generate-token`);
return response.data.token;
}
async signIn(credentials) {
const response = await axios.post(`${this.apiUrl}/signin`, credentials);
return response.data.token;
}
async logout(token) {
await axios.post(`${this.apiUrl}/logout`, { token });
}
}
export default AuthService.getInstance();
return context;
};
import usePeableSession from "./hooks/usePeableSession";
import getUserById from "./hooks/getUserById";
import AuthService from "./hooks/AuthService";
export { usePeableSession, getUserById, AuthService };
import AuthProvider from "./AuthProvider";
export { usePeableSession, getUserById, AuthProvider };
//# sourceMappingURL=index.d.ts.map
import usePeableSession from "./hooks/usePeableSession";
import getUserById from "./hooks/getUserById";
import AuthService from "./hooks/AuthService";
export { usePeableSession, getUserById, AuthService };
import AuthProvider from "./AuthProvider";
export { usePeableSession, getUserById, AuthProvider };
{
"name": "@peable/services",
"version": "0.0.66",
"version": "0.0.67",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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