@supabase/gotrue-js
Advanced tools
Comparing version 1.14.0 to 1.15.0
@@ -118,2 +118,12 @@ import { Session, Provider, UserAttributes, CookieOptions, User } from './lib/types'; | ||
/** | ||
* Delete an user. | ||
* @param userUID The user uid you want to remove. | ||
* @param jwt A valid, logged-in JWT. | ||
*/ | ||
deleteUser(userUID: string, jwt: string): Promise<{ | ||
user: User | null; | ||
data: User | null; | ||
error: Error | null; | ||
}>; | ||
/** | ||
* Generates a new JWT. | ||
@@ -120,0 +130,0 @@ * @param refreshToken A valid refresh token that was returned on login. |
@@ -208,2 +208,20 @@ "use strict"; | ||
/** | ||
* Delete an user. | ||
* @param userUID The user uid you want to remove. | ||
* @param jwt A valid, logged-in JWT. | ||
*/ | ||
deleteUser(userUID, jwt) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const data = yield fetch_1.remove(`${this.url}/admin/users/${userUID}`, {}, { | ||
headers: this._createRequestHeaders(jwt), | ||
}); | ||
return { user: data, data, error: null }; | ||
} | ||
catch (error) { | ||
return { user: null, data: null, error }; | ||
} | ||
}); | ||
} | ||
/** | ||
* Generates a new JWT. | ||
@@ -210,0 +228,0 @@ * @param refreshToken A valid refresh token that was returned on login. |
@@ -104,2 +104,12 @@ import GoTrueApi from './GoTrueApi'; | ||
/** | ||
* Delete an user. | ||
*/ | ||
deleteUser({ userUID, }: { | ||
userUID: string; | ||
}): Promise<{ | ||
data: User | null; | ||
user: User | null; | ||
error: Error | null; | ||
}>; | ||
/** | ||
* Sets the session data from refresh_token and returns current Session and Error | ||
@@ -106,0 +116,0 @@ * @param refresh_token a JWT token |
@@ -197,2 +197,26 @@ "use strict"; | ||
/** | ||
* Delete an user. | ||
*/ | ||
deleteUser({ userUID, }) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (!((_a = this.currentSession) === null || _a === void 0 ? void 0 : _a.access_token)) | ||
throw new Error('Not logged in.'); | ||
const { error, user } = yield this.api.deleteUser(userUID, this.currentSession.access_token); | ||
if (error) | ||
throw error; | ||
if (!user) | ||
throw Error('Invalid user data.'); | ||
const session = Object.assign(Object.assign({}, this.currentSession), { user }); | ||
this._saveSession(session); | ||
this._notifyAllSubscribers('USER_DELETED'); | ||
return { data: user, user, error: null }; | ||
} | ||
catch (error) { | ||
return { data: null, user: null, error }; | ||
} | ||
}); | ||
} | ||
/** | ||
* Sets the session data from refresh_token and returns current Session and Error | ||
@@ -199,0 +223,0 @@ * @param refresh_token a JWT token |
@@ -7,6 +7,7 @@ export interface FetchOptions { | ||
} | ||
export declare type RequestMethodType = 'GET' | 'POST' | 'PUT'; | ||
export declare type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; | ||
export declare function get(url: string, options?: FetchOptions): Promise<any>; | ||
export declare function post(url: string, body: object, options?: FetchOptions): Promise<any>; | ||
export declare function put(url: string, body: object, options?: FetchOptions): Promise<any>; | ||
export declare function remove(url: string, body: object, options?: FetchOptions): Promise<any>; | ||
//# sourceMappingURL=fetch.d.ts.map |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.put = exports.post = exports.get = void 0; | ||
exports.remove = exports.put = exports.post = exports.get = void 0; | ||
const cross_fetch_1 = __importDefault(require("cross-fetch")); | ||
@@ -73,2 +73,8 @@ const _getErrorMessage = (err) => err.msg || err.message || err.error_description || err.error || JSON.stringify(err); | ||
exports.put = put; | ||
function remove(url, body, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return _handleRequest('DELETE', url, options, body); | ||
}); | ||
} | ||
exports.remove = remove; | ||
//# sourceMappingURL=fetch.js.map |
export declare type Provider = 'azure' | 'bitbucket' | 'facebook' | 'github' | 'gitlab' | 'google'; | ||
export declare type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT' | 'USER_UPDATED' | 'PASSWORD_RECOVERY'; | ||
export declare type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT' | 'USER_UPDATED' | 'USER_DELETED' | 'PASSWORD_RECOVERY'; | ||
export interface Session { | ||
@@ -4,0 +4,0 @@ provider_token?: string | null; |
@@ -118,2 +118,12 @@ import { Session, Provider, UserAttributes, CookieOptions, User } from './lib/types'; | ||
/** | ||
* Delete an user. | ||
* @param userUID The user uid you want to remove. | ||
* @param jwt A valid, logged-in JWT. | ||
*/ | ||
deleteUser(userUID: string, jwt: string): Promise<{ | ||
user: User | null; | ||
data: User | null; | ||
error: Error | null; | ||
}>; | ||
/** | ||
* Generates a new JWT. | ||
@@ -120,0 +130,0 @@ * @param refreshToken A valid refresh token that was returned on login. |
@@ -10,3 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { get, post, put } from './lib/fetch'; | ||
import { get, post, put, remove } from './lib/fetch'; | ||
import { COOKIE_OPTIONS } from './lib/constants'; | ||
@@ -207,2 +207,20 @@ import { setCookie, deleteCookie } from './lib/cookies'; | ||
/** | ||
* Delete an user. | ||
* @param userUID The user uid you want to remove. | ||
* @param jwt A valid, logged-in JWT. | ||
*/ | ||
deleteUser(userUID, jwt) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const data = yield remove(`${this.url}/admin/users/${userUID}`, {}, { | ||
headers: this._createRequestHeaders(jwt), | ||
}); | ||
return { user: data, data, error: null }; | ||
} | ||
catch (error) { | ||
return { user: null, data: null, error }; | ||
} | ||
}); | ||
} | ||
/** | ||
* Generates a new JWT. | ||
@@ -209,0 +227,0 @@ * @param refreshToken A valid refresh token that was returned on login. |
@@ -104,2 +104,12 @@ import GoTrueApi from './GoTrueApi'; | ||
/** | ||
* Delete an user. | ||
*/ | ||
deleteUser({ userUID, }: { | ||
userUID: string; | ||
}): Promise<{ | ||
data: User | null; | ||
user: User | null; | ||
error: Error | null; | ||
}>; | ||
/** | ||
* Sets the session data from refresh_token and returns current Session and Error | ||
@@ -106,0 +116,0 @@ * @param refresh_token a JWT token |
@@ -192,2 +192,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
/** | ||
* Delete an user. | ||
*/ | ||
deleteUser({ userUID, }) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (!((_a = this.currentSession) === null || _a === void 0 ? void 0 : _a.access_token)) | ||
throw new Error('Not logged in.'); | ||
const { error, user } = yield this.api.deleteUser(userUID, this.currentSession.access_token); | ||
if (error) | ||
throw error; | ||
if (!user) | ||
throw Error('Invalid user data.'); | ||
const session = Object.assign(Object.assign({}, this.currentSession), { user }); | ||
this._saveSession(session); | ||
this._notifyAllSubscribers('USER_DELETED'); | ||
return { data: user, user, error: null }; | ||
} | ||
catch (error) { | ||
return { data: null, user: null, error }; | ||
} | ||
}); | ||
} | ||
/** | ||
* Sets the session data from refresh_token and returns current Session and Error | ||
@@ -194,0 +218,0 @@ * @param refresh_token a JWT token |
@@ -7,6 +7,7 @@ export interface FetchOptions { | ||
} | ||
export declare type RequestMethodType = 'GET' | 'POST' | 'PUT'; | ||
export declare type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; | ||
export declare function get(url: string, options?: FetchOptions): Promise<any>; | ||
export declare function post(url: string, body: object, options?: FetchOptions): Promise<any>; | ||
export declare function put(url: string, body: object, options?: FetchOptions): Promise<any>; | ||
export declare function remove(url: string, body: object, options?: FetchOptions): Promise<any>; | ||
//# sourceMappingURL=fetch.d.ts.map |
@@ -63,2 +63,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
export function remove(url, body, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return _handleRequest('DELETE', url, options, body); | ||
}); | ||
} | ||
//# sourceMappingURL=fetch.js.map |
export declare type Provider = 'azure' | 'bitbucket' | 'facebook' | 'github' | 'gitlab' | 'google'; | ||
export declare type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT' | 'USER_UPDATED' | 'PASSWORD_RECOVERY'; | ||
export declare type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT' | 'USER_UPDATED' | 'USER_DELETED' | 'PASSWORD_RECOVERY'; | ||
export interface Session { | ||
@@ -4,0 +4,0 @@ provider_token?: string | null; |
{ | ||
"name": "@supabase/gotrue-js", | ||
"version": "1.14.0", | ||
"version": "1.15.0", | ||
"description": "Isomorphic GoTrue client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
import { get, post, put } from './lib/fetch' | ||
import { get, post, put, remove } from './lib/fetch' | ||
import { Session, Provider, UserAttributes, CookieOptions, User } from './lib/types' | ||
@@ -246,2 +246,25 @@ import { COOKIE_OPTIONS } from './lib/constants' | ||
/** | ||
* Delete an user. | ||
* @param userUID The user uid you want to remove. | ||
* @param jwt A valid, logged-in JWT. | ||
*/ | ||
async deleteUser( | ||
userUID: string, | ||
jwt: string | ||
): Promise<{ user: User | null; data: User | null; error: Error | null }> { | ||
try { | ||
const data: any = await remove( | ||
`${this.url}/admin/users/${userUID}`, | ||
{}, | ||
{ | ||
headers: this._createRequestHeaders(jwt), | ||
} | ||
) | ||
return { user: data, data, error: null } | ||
} catch (error) { | ||
return { user: null, data: null, error } | ||
} | ||
} | ||
/** | ||
* Generates a new JWT. | ||
@@ -248,0 +271,0 @@ * @param refreshToken A valid refresh token that was returned on login. |
@@ -255,2 +255,27 @@ import GoTrueApi from './GoTrueApi' | ||
/** | ||
* Delete an user. | ||
*/ | ||
async deleteUser({ | ||
userUID, | ||
}: { | ||
userUID: string | ||
}): Promise<{ data: User | null; user: User | null; error: Error | null }> { | ||
try { | ||
if (!this.currentSession?.access_token) throw new Error('Not logged in.') | ||
const { error, user } = await this.api.deleteUser(userUID, this.currentSession.access_token) | ||
if (error) throw error | ||
if (!user) throw Error('Invalid user data.') | ||
const session = { ...this.currentSession, user } | ||
this._saveSession(session) | ||
this._notifyAllSubscribers('USER_DELETED') | ||
return { data: user, user, error: null } | ||
} catch (error) { | ||
return { data: null, user: null, error } | ||
} | ||
} | ||
/** | ||
* Sets the session data from refresh_token and returns current Session and Error | ||
@@ -257,0 +282,0 @@ * @param refresh_token a JWT token |
@@ -10,3 +10,3 @@ import fetch from 'cross-fetch' | ||
export type RequestMethodType = 'GET' | 'POST' | 'PUT' | ||
export type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | ||
@@ -70,1 +70,5 @@ const _getErrorMessage = (err: any): string => | ||
} | ||
export async function remove(url: string, body: object, options?: FetchOptions): Promise<any> { | ||
return _handleRequest('DELETE', url, options, body) | ||
} |
export type Provider = 'azure' | 'bitbucket' | 'facebook' | 'github' | 'gitlab' | 'google' | ||
export type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT' | 'USER_UPDATED' | 'PASSWORD_RECOVERY' | ||
export type AuthChangeEvent = | ||
| 'SIGNED_IN' | ||
| 'SIGNED_OUT' | ||
| 'USER_UPDATED' | ||
| 'USER_DELETED' | ||
| 'PASSWORD_RECOVERY' | ||
@@ -5,0 +10,0 @@ export interface Session { |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
242530
4368