refactor: fix handling of check by creating a handleCheckResponse wrapper to translate success to authenticated
This commit is contained in:
parent
b3f0044723
commit
bec75e63ee
|
@ -54,6 +54,10 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
||||||
successCb?: () => void;
|
successCb?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CheckResponseResult extends ResponseResult {
|
||||||
|
authenticated?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
const handleResponse = (result: ResponseResult): AuthActionResponse => {
|
const handleResponse = (result: ResponseResult): AuthActionResponse => {
|
||||||
if (result.ret) {
|
if (result.ret) {
|
||||||
if (result.ret instanceof Error) {
|
if (result.ret instanceof Error) {
|
||||||
|
@ -79,6 +83,17 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleCheckResponse = (result: CheckResponseResult): CheckResponse => {
|
||||||
|
const response = handleResponse(result);
|
||||||
|
const success = response.success;
|
||||||
|
delete response.success;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...response,
|
||||||
|
authenticated: success
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
async login(params: AuthFormRequest): Promise<AuthActionResponse> {
|
async login(params: AuthFormRequest): Promise<AuthActionResponse> {
|
||||||
const ret = await sdk.account().login({
|
const ret = await sdk.account().login({
|
||||||
|
@ -105,7 +120,7 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
||||||
async check(params?: any): Promise<CheckResponse> {
|
async check(params?: any): Promise<CheckResponse> {
|
||||||
const ret = await sdk.account().ping();
|
const ret = await sdk.account().ping();
|
||||||
|
|
||||||
return handleResponse({ret, redirectToError: "/login", successCb: maybeSetupAuth});
|
return handleCheckResponse({ret, redirectToError: "/login", successCb: maybeSetupAuth});
|
||||||
},
|
},
|
||||||
|
|
||||||
async onError(error: any): Promise<OnErrorResponse> {
|
async onError(error: any): Promise<OnErrorResponse> {
|
||||||
|
|
Loading…
Reference in New Issue