mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Replace basic auth with cookie authentication (#440)
* Add logout functionality and button * Make session age configurable
This commit is contained in:
@@ -2,7 +2,9 @@ import ApolloClient from "apollo-client";
|
||||
import { WebSocketLink } from "apollo-link-ws";
|
||||
import { InMemoryCache, NormalizedCacheObject } from "apollo-cache-inmemory";
|
||||
import { HttpLink } from "apollo-link-http";
|
||||
import { split } from "apollo-link";
|
||||
import { onError } from "apollo-link-error";
|
||||
import { ServerError } from "apollo-link-http-common";
|
||||
import { split, from } from "apollo-link";
|
||||
import { getMainDefinition } from "apollo-utilities";
|
||||
import { ListFilterModel } from "../models/list-filter/filter";
|
||||
import * as GQL from "./generated-graphql";
|
||||
@@ -51,7 +53,15 @@ export class StashService {
|
||||
},
|
||||
});
|
||||
|
||||
const link = split(
|
||||
const errorLink = onError(({ networkError }) => {
|
||||
// handle unauthorized error by redirecting to the login page
|
||||
if (networkError && (networkError as ServerError).statusCode === 401) {
|
||||
// redirect to login page
|
||||
window.location.href = "/login";
|
||||
}
|
||||
});
|
||||
|
||||
const splitLink = split(
|
||||
({ query }) => {
|
||||
const definition = getMainDefinition(query);
|
||||
return (
|
||||
@@ -63,6 +73,8 @@ export class StashService {
|
||||
httpLink
|
||||
);
|
||||
|
||||
const link = from([errorLink, splitLink]);
|
||||
|
||||
StashService.cache = new InMemoryCache();
|
||||
StashService.client = new ApolloClient({
|
||||
link,
|
||||
|
||||
Reference in New Issue
Block a user