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

@supabase/gotrue-js

Package Overview
Dependencies
Maintainers
3
Versions
300
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@supabase/gotrue-js - npm Package Compare versions

Comparing version 1.5.10 to 1.6.0

4

dist/main/GoTrueApi.d.ts

@@ -1,2 +0,2 @@

import { Provider, UserAttributes } from './lib/types';
import { Session, Provider, UserAttributes } from './lib/types';
export default class GoTrueApi {

@@ -26,3 +26,3 @@ url: string;

signInWithEmail(email: string, password: string): Promise<{
data: any;
data: Session;
error: null;

@@ -29,0 +29,0 @@ } | {

@@ -43,3 +43,3 @@ "use strict";

let data = yield fetch_1.post(`${this.url}/token?grant_type=password`, { email, password }, { headers: this.headers });
return { data, error: null };
return { data: data, error: null };
}

@@ -46,0 +46,0 @@ catch (error) {

import GoTrueApi from './GoTrueApi';
import { Session, User, UserAttributes, Provider, Subscription } from './lib/types';
import { Session, User, UserAttributes, Provider, Subscription, AuthChangeEvent } from './lib/types';
export default class GoTrueClient {
api: GoTrueApi;
currentUser: User | null;
currentSession?: Session | null;
autoRefreshToken: boolean;
persistSession: boolean;
localStorage: Storage;
stateChangeEmmitters: Map<string, Subscription>;
/**
* The currently logged in user or null.
*/
protected currentUser: User | null;
/**
* The session object for the currently logged in user or null.
*/
protected currentSession: Session | null;
protected api: GoTrueApi;
protected autoRefreshToken: boolean;
protected persistSession: boolean;
protected localStorage: Storage;
protected stateChangeEmmitters: Map<string, Subscription>;
/**
* Create a new client for use in the browser.

@@ -40,6 +46,4 @@ * @param options.url The URL of the GoTrue server.

}): Promise<{
data: any;
error: null;
} | {
data: null;
data: Session | null;
user: User | null;
error: any;

@@ -59,7 +63,7 @@ }>;

}): Promise<{
data: null;
data: Session | null;
user: User | null;
provider?: Provider;
url?: string | null;
error: any;
} | {
data: any;
error: null;
}>;

@@ -69,8 +73,21 @@ /**

*/
user(): Promise<{
user(): {
data: User | null;
error: null;
} | {
data: null;
user: User | null;
error: any;
};
/**
* Returns the session data, if there is an active session.
*/
session(): {
data: Session | null;
error: any;
};
/**
* Force refreshes the session including the user data in case it was updated in a different session.
*/
refreshSession(): Promise<{
data: Session | null;
user: User | null;
error: any;
}>;

@@ -82,5 +99,3 @@ /**

data: User | null;
error: null;
} | {
data: null;
user: User | null;
error: any;

@@ -95,6 +110,3 @@ }>;

}): Promise<{
data: Session;
error: null;
} | {
data: null;
data: Session | null;
error: any;

@@ -105,4 +117,3 @@ }>;

*/
signOut(): Promise<true | {
data: null;
signOut(): Promise<{
error: any;

@@ -114,7 +125,4 @@ }>;

*/
onAuthStateChange(callback: Function): {
data: Subscription | undefined;
error: null;
} | {
data: null;
onAuthStateChange(callback: (event: AuthChangeEvent, session: Session | null) => void): {
data: Subscription | null;
error: any;

@@ -121,0 +129,0 @@ };

@@ -18,3 +18,2 @@ "use strict";

const constants_1 = require("./lib/constants");
const types_1 = require("./lib/types");
const DEFAULT_OPTIONS = {

@@ -74,8 +73,8 @@ url: constants_1.GOTRUE_URL,

this._saveSession(data);
this._notifyAllSubscribers(types_1.AuthChangeEvent.SIGNED_IN);
this._notifyAllSubscribers('SIGNED_IN');
}
return { data, error: null };
return { data, user: data.user, error: null };
}
catch (error) {
return { data: null, error };
return { data: null, user: null, error };
}

@@ -104,3 +103,3 @@ });

catch (error) {
return { data: null, error };
return { data: null, user: null, error };
}

@@ -114,2 +113,30 @@ });

var _a;
try {
if (!((_a = this.currentSession) === null || _a === void 0 ? void 0 : _a.access_token))
throw new Error('Not logged in.');
return { data: this.currentUser, user: this.currentUser, error: null };
}
catch (error) {
return { data: null, user: null, error };
}
}
/**
* Returns the session data, if there is an active session.
*/
session() {
var _a;
try {
if (!((_a = this.currentSession) === null || _a === void 0 ? void 0 : _a.access_token))
throw new Error('Not logged in.');
return { data: this.currentSession, error: null };
}
catch (error) {
return { data: null, error };
}
}
/**
* Force refreshes the session including the user data in case it was updated in a different session.
*/
refreshSession() {
var _a;
return __awaiter(this, void 0, void 0, function* () {

@@ -119,2 +146,3 @@ try {

throw new Error('Not logged in.');
yield this._callRefreshToken();
let { data, error } = yield this.api.getUser(this.currentSession.access_token);

@@ -124,6 +152,6 @@ if (error)

this.currentUser = data;
return { data: this.currentUser, error: null };
return { data: this.currentSession, user: this.currentUser, error: null };
}
catch (error) {
return { data: null, error };
return { data: null, user: null, error };
}

@@ -145,7 +173,7 @@ });

this.currentUser = data;
this._notifyAllSubscribers(types_1.AuthChangeEvent.USER_UPDATED);
return { data: this.currentUser, error: null };
this._notifyAllSubscribers('USER_UPDATED');
return { data, user: this.currentUser, error: null };
}
catch (error) {
return { data: null, error };
return { data: null, user: null, error };
}

@@ -190,3 +218,3 @@ });

this._saveSession(session);
this._notifyAllSubscribers(types_1.AuthChangeEvent.SIGNED_IN);
this._notifyAllSubscribers('SIGNED_IN');
}

@@ -210,7 +238,7 @@ return { data: session, error: null };

this._removeSession();
this._notifyAllSubscribers(types_1.AuthChangeEvent.SIGNED_OUT);
return true;
this._notifyAllSubscribers('SIGNED_OUT');
return { error: null };
}
catch (error) {
return { data: null, error };
return { error };
}

@@ -230,6 +258,8 @@ });

callback,
unsubscribe: () => self.stateChangeEmmitters.delete(id),
unsubscribe: () => {
self.stateChangeEmmitters.delete(id);
},
};
this.stateChangeEmmitters.set(id, subscription);
return { data: this.stateChangeEmmitters.get(id), error: null };
return { data: subscription, error: null };
}

@@ -245,13 +275,12 @@ catch (error) {

let { data, error } = yield this.api.signInWithEmail(email, password);
if (!!error)
return { data: null, error };
if (error || !data)
return { data: null, user: null, error };
if ((_a = data === null || data === void 0 ? void 0 : data.user) === null || _a === void 0 ? void 0 : _a.confirmed_at) {
this._saveSession(data);
this._notifyAllSubscribers(types_1.AuthChangeEvent.SIGNED_IN);
this._notifyAllSubscribers('SIGNED_IN');
}
return { data, error: null };
return { data, user: data.user, error: null };
}
catch (error) {
console.log('error_handeEmailSignIn', error);
return { data: null, error };
return { data: null, user: null, error };
}

@@ -267,3 +296,3 @@ });

}
return { data: url, error: null };
return { provider, url, data: null, user: null, error: null };
}

@@ -273,5 +302,5 @@ catch (error) {

if (!!url)
return { data: url, error: null };
return { provider, url, data: null, user: null, error: null };
else
return { data: null, error };
return { data: null, user: null, error };
}

@@ -278,0 +307,0 @@ }

@@ -1,12 +0,3 @@

export declare enum Provider {
BITBUCKET = "bitbucket",
GITHUB = "github",
GITLAB = "gitlab",
GOOGLE = "google"
}
export declare enum AuthChangeEvent {
SIGNED_IN = "SIGNED_IN",
SIGNED_OUT = "SIGNED_OUT",
USER_UPDATED = "USER_UPDATED"
}
export declare type Provider = 'bitbucket' | 'github' | 'gitlab' | 'google';
export declare type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT' | 'USER_UPDATED';
export interface Session {

@@ -21,4 +12,9 @@ access_token: string;

id: string;
app_metadata: any;
user_metadata: any;
app_metadata: {
provider?: string;
[key: string]: any;
};
user_metadata: {
[key: string]: any;
};
aud: string;

@@ -58,8 +54,8 @@ email?: string;

*/
callback: Function;
callback: (event: AuthChangeEvent, session: Session | null) => void;
/**
* Call this to remove the listener.
*/
unsubscribe: Function;
unsubscribe: () => void;
}
//# sourceMappingURL=types.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthChangeEvent = exports.Provider = void 0;
var Provider;
(function (Provider) {
Provider["BITBUCKET"] = "bitbucket";
Provider["GITHUB"] = "github";
Provider["GITLAB"] = "gitlab";
Provider["GOOGLE"] = "google";
})(Provider = exports.Provider || (exports.Provider = {}));
var AuthChangeEvent;
(function (AuthChangeEvent) {
AuthChangeEvent["SIGNED_IN"] = "SIGNED_IN";
AuthChangeEvent["SIGNED_OUT"] = "SIGNED_OUT";
AuthChangeEvent["USER_UPDATED"] = "USER_UPDATED";
})(AuthChangeEvent = exports.AuthChangeEvent || (exports.AuthChangeEvent = {}));
//# sourceMappingURL=types.js.map

@@ -1,2 +0,2 @@

import { Provider, UserAttributes } from './lib/types';
import { Session, Provider, UserAttributes } from './lib/types';
export default class GoTrueApi {

@@ -26,3 +26,3 @@ url: string;

signInWithEmail(email: string, password: string): Promise<{
data: any;
data: Session;
error: null;

@@ -29,0 +29,0 @@ } | {

@@ -41,3 +41,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

let data = yield post(`${this.url}/token?grant_type=password`, { email, password }, { headers: this.headers });
return { data, error: null };
return { data: data, error: null };
}

@@ -44,0 +44,0 @@ catch (error) {

import GoTrueApi from './GoTrueApi';
import { Session, User, UserAttributes, Provider, Subscription } from './lib/types';
import { Session, User, UserAttributes, Provider, Subscription, AuthChangeEvent } from './lib/types';
export default class GoTrueClient {
api: GoTrueApi;
currentUser: User | null;
currentSession?: Session | null;
autoRefreshToken: boolean;
persistSession: boolean;
localStorage: Storage;
stateChangeEmmitters: Map<string, Subscription>;
/**
* The currently logged in user or null.
*/
protected currentUser: User | null;
/**
* The session object for the currently logged in user or null.
*/
protected currentSession: Session | null;
protected api: GoTrueApi;
protected autoRefreshToken: boolean;
protected persistSession: boolean;
protected localStorage: Storage;
protected stateChangeEmmitters: Map<string, Subscription>;
/**
* Create a new client for use in the browser.

@@ -40,6 +46,4 @@ * @param options.url The URL of the GoTrue server.

}): Promise<{
data: any;
error: null;
} | {
data: null;
data: Session | null;
user: User | null;
error: any;

@@ -59,7 +63,7 @@ }>;

}): Promise<{
data: null;
data: Session | null;
user: User | null;
provider?: Provider;
url?: string | null;
error: any;
} | {
data: any;
error: null;
}>;

@@ -69,8 +73,21 @@ /**

*/
user(): Promise<{
user(): {
data: User | null;
error: null;
} | {
data: null;
user: User | null;
error: any;
};
/**
* Returns the session data, if there is an active session.
*/
session(): {
data: Session | null;
error: any;
};
/**
* Force refreshes the session including the user data in case it was updated in a different session.
*/
refreshSession(): Promise<{
data: Session | null;
user: User | null;
error: any;
}>;

@@ -82,5 +99,3 @@ /**

data: User | null;
error: null;
} | {
data: null;
user: User | null;
error: any;

@@ -95,6 +110,3 @@ }>;

}): Promise<{
data: Session;
error: null;
} | {
data: null;
data: Session | null;
error: any;

@@ -105,4 +117,3 @@ }>;

*/
signOut(): Promise<true | {
data: null;
signOut(): Promise<{
error: any;

@@ -114,7 +125,4 @@ }>;

*/
onAuthStateChange(callback: Function): {
data: Subscription | undefined;
error: null;
} | {
data: null;
onAuthStateChange(callback: (event: AuthChangeEvent, session: Session | null) => void): {
data: Subscription | null;
error: any;

@@ -121,0 +129,0 @@ };

@@ -13,3 +13,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { GOTRUE_URL, DEFAULT_HEADERS, STORAGE_KEY } from './lib/constants';
import { AuthChangeEvent } from './lib/types';
const DEFAULT_OPTIONS = {

@@ -69,8 +68,8 @@ url: GOTRUE_URL,

this._saveSession(data);
this._notifyAllSubscribers(AuthChangeEvent.SIGNED_IN);
this._notifyAllSubscribers('SIGNED_IN');
}
return { data, error: null };
return { data, user: data.user, error: null };
}
catch (error) {
return { data: null, error };
return { data: null, user: null, error };
}

@@ -99,3 +98,3 @@ });

catch (error) {
return { data: null, error };
return { data: null, user: null, error };
}

@@ -109,2 +108,30 @@ });

var _a;
try {
if (!((_a = this.currentSession) === null || _a === void 0 ? void 0 : _a.access_token))
throw new Error('Not logged in.');
return { data: this.currentUser, user: this.currentUser, error: null };
}
catch (error) {
return { data: null, user: null, error };
}
}
/**
* Returns the session data, if there is an active session.
*/
session() {
var _a;
try {
if (!((_a = this.currentSession) === null || _a === void 0 ? void 0 : _a.access_token))
throw new Error('Not logged in.');
return { data: this.currentSession, error: null };
}
catch (error) {
return { data: null, error };
}
}
/**
* Force refreshes the session including the user data in case it was updated in a different session.
*/
refreshSession() {
var _a;
return __awaiter(this, void 0, void 0, function* () {

@@ -114,2 +141,3 @@ try {

throw new Error('Not logged in.');
yield this._callRefreshToken();
let { data, error } = yield this.api.getUser(this.currentSession.access_token);

@@ -119,6 +147,6 @@ if (error)

this.currentUser = data;
return { data: this.currentUser, error: null };
return { data: this.currentSession, user: this.currentUser, error: null };
}
catch (error) {
return { data: null, error };
return { data: null, user: null, error };
}

@@ -140,7 +168,7 @@ });

this.currentUser = data;
this._notifyAllSubscribers(AuthChangeEvent.USER_UPDATED);
return { data: this.currentUser, error: null };
this._notifyAllSubscribers('USER_UPDATED');
return { data, user: this.currentUser, error: null };
}
catch (error) {
return { data: null, error };
return { data: null, user: null, error };
}

@@ -185,3 +213,3 @@ });

this._saveSession(session);
this._notifyAllSubscribers(AuthChangeEvent.SIGNED_IN);
this._notifyAllSubscribers('SIGNED_IN');
}

@@ -205,7 +233,7 @@ return { data: session, error: null };

this._removeSession();
this._notifyAllSubscribers(AuthChangeEvent.SIGNED_OUT);
return true;
this._notifyAllSubscribers('SIGNED_OUT');
return { error: null };
}
catch (error) {
return { data: null, error };
return { error };
}

@@ -225,6 +253,8 @@ });

callback,
unsubscribe: () => self.stateChangeEmmitters.delete(id),
unsubscribe: () => {
self.stateChangeEmmitters.delete(id);
},
};
this.stateChangeEmmitters.set(id, subscription);
return { data: this.stateChangeEmmitters.get(id), error: null };
return { data: subscription, error: null };
}

@@ -240,13 +270,12 @@ catch (error) {

let { data, error } = yield this.api.signInWithEmail(email, password);
if (!!error)
return { data: null, error };
if (error || !data)
return { data: null, user: null, error };
if ((_a = data === null || data === void 0 ? void 0 : data.user) === null || _a === void 0 ? void 0 : _a.confirmed_at) {
this._saveSession(data);
this._notifyAllSubscribers(AuthChangeEvent.SIGNED_IN);
this._notifyAllSubscribers('SIGNED_IN');
}
return { data, error: null };
return { data, user: data.user, error: null };
}
catch (error) {
console.log('error_handeEmailSignIn', error);
return { data: null, error };
return { data: null, user: null, error };
}

@@ -262,3 +291,3 @@ });

}
return { data: url, error: null };
return { provider, url, data: null, user: null, error: null };
}

@@ -268,5 +297,5 @@ catch (error) {

if (!!url)
return { data: url, error: null };
return { provider, url, data: null, user: null, error: null };
else
return { data: null, error };
return { data: null, user: null, error };
}

@@ -273,0 +302,0 @@ }

@@ -1,12 +0,3 @@

export declare enum Provider {
BITBUCKET = "bitbucket",
GITHUB = "github",
GITLAB = "gitlab",
GOOGLE = "google"
}
export declare enum AuthChangeEvent {
SIGNED_IN = "SIGNED_IN",
SIGNED_OUT = "SIGNED_OUT",
USER_UPDATED = "USER_UPDATED"
}
export declare type Provider = 'bitbucket' | 'github' | 'gitlab' | 'google';
export declare type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT' | 'USER_UPDATED';
export interface Session {

@@ -21,4 +12,9 @@ access_token: string;

id: string;
app_metadata: any;
user_metadata: any;
app_metadata: {
provider?: string;
[key: string]: any;
};
user_metadata: {
[key: string]: any;
};
aud: string;

@@ -58,8 +54,8 @@ email?: string;

*/
callback: Function;
callback: (event: AuthChangeEvent, session: Session | null) => void;
/**
* Call this to remove the listener.
*/
unsubscribe: Function;
unsubscribe: () => void;
}
//# sourceMappingURL=types.d.ts.map

@@ -1,14 +0,2 @@

export var Provider;
(function (Provider) {
Provider["BITBUCKET"] = "bitbucket";
Provider["GITHUB"] = "github";
Provider["GITLAB"] = "gitlab";
Provider["GOOGLE"] = "google";
})(Provider || (Provider = {}));
export var AuthChangeEvent;
(function (AuthChangeEvent) {
AuthChangeEvent["SIGNED_IN"] = "SIGNED_IN";
AuthChangeEvent["SIGNED_OUT"] = "SIGNED_OUT";
AuthChangeEvent["USER_UPDATED"] = "USER_UPDATED";
})(AuthChangeEvent || (AuthChangeEvent = {}));
export {};
//# sourceMappingURL=types.js.map
{
"name": "@supabase/gotrue-js",
"version": "1.5.10",
"version": "1.6.0",
"description": "Isomorphic GoTrue client",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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