New login screen (#1331)
* wip * feat: first draft of auth.config * chore: auth methodS * chore: styling * styling, styling, styling * feat: Auth notices * chore: Remove server-rendered pages, move shared/components -> components * lint * cleanup * cleanup * fix: Remove unused component * fix: Ensure env variables in prod too * style tweaks * fix: Entering SSO email into login form fails fix: Tweak language around guest signin
This commit is contained in:
@ -10,13 +10,27 @@ import Team from "models/Team";
|
||||
|
||||
const AUTH_STORE = "AUTH_STORE";
|
||||
|
||||
type Service = {
|
||||
id: string,
|
||||
name: string,
|
||||
authUrl: string,
|
||||
};
|
||||
|
||||
type Config = {
|
||||
name?: string,
|
||||
hostname?: string,
|
||||
services: Service[],
|
||||
};
|
||||
|
||||
export default class AuthStore {
|
||||
@observable user: ?User;
|
||||
@observable team: ?Team;
|
||||
@observable token: ?string;
|
||||
@observable lastSignedIn: ?string;
|
||||
@observable isSaving: boolean = false;
|
||||
@observable isSuspended: boolean = false;
|
||||
@observable suspendedContactEmail: ?string;
|
||||
@observable config: ?Config;
|
||||
rootStore: RootStore;
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
@ -32,8 +46,12 @@ export default class AuthStore {
|
||||
this.user = new User(data.user);
|
||||
this.team = new Team(data.team);
|
||||
this.token = getCookie("accessToken");
|
||||
this.lastSignedIn = getCookie("lastSignedIn");
|
||||
setImmediate(() => this.fetchConfig());
|
||||
|
||||
if (this.token) setImmediate(() => this.fetch());
|
||||
if (this.token) {
|
||||
setImmediate(() => this.fetch());
|
||||
}
|
||||
|
||||
autorun(() => {
|
||||
try {
|
||||
@ -63,6 +81,13 @@ export default class AuthStore {
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
fetchConfig = async () => {
|
||||
const res = await client.post("/auth.config");
|
||||
invariant(res && res.data, "Config not available");
|
||||
this.config = res.data;
|
||||
};
|
||||
|
||||
@action
|
||||
fetch = async () => {
|
||||
try {
|
||||
@ -158,10 +183,16 @@ export default class AuthStore {
|
||||
})
|
||||
);
|
||||
|
||||
this.token = null;
|
||||
|
||||
// if this logout was forced from an authenticated route then
|
||||
// save the current path so we can go back there once signed in
|
||||
if (savePath) {
|
||||
setCookie("postLoginRedirectPath", window.location.pathname);
|
||||
const pathName = window.location.pathname;
|
||||
|
||||
if (pathName !== "/" && pathName !== "/create") {
|
||||
setCookie("postLoginRedirectPath", pathName);
|
||||
}
|
||||
}
|
||||
|
||||
// remove authentication token itself
|
||||
@ -178,8 +209,5 @@ export default class AuthStore {
|
||||
});
|
||||
this.team = null;
|
||||
}
|
||||
|
||||
// add a timestamp to force reload from server
|
||||
window.location.href = `${BASE_URL}?done=${new Date().getTime()}`;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user