Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
[NC]: Window redirection to sign up when user is logged out (#74)
Browse files Browse the repository at this point in the history
* [NC]: Adds window redirection to sign up when user is logged out

* [NC]:biome fixes
  • Loading branch information
nicolaschapur authored Jun 25, 2024
1 parent bf95602 commit e285ec8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
7 changes: 7 additions & 0 deletions apps/mocksi-lite/content/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
MOCKSI_RECORDING_STATE,
RecordingState,
STORAGE_CHANGE_EVENT,
SignupURL,
} from "../consts";
import { getEmail, sendMessage, setRootPosition } from "../utils";
import ContentApp from "./ContentApp";
Expand Down Expand Up @@ -47,6 +48,12 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (recordingState === RecordingState.HIDDEN) {
sendMessage("updateToPlayIcon");
}
if (
recordingState === RecordingState.UNAUTHORIZED &&
window.location.origin !== SignupURL
) {
window.open(SignupURL);
}
setRootPosition(state);
root.render(<ContentApp isOpen={true} email={email || ""} />);
});
Expand Down
27 changes: 22 additions & 5 deletions apps/mocksi-lite/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DOMManipulator } from "@repo/dodom";
import auth0, { type WebAuth } from "auth0-js";
import sanitizeHtml from "sanitize-html";
import MocksiRollbar from "./MocksiRollbar";
import type { Alteration } from "./background";
Expand Down Expand Up @@ -30,6 +31,15 @@ type DOMModificationsType = {
[querySelector: string]: DomAlteration;
};

const authOptions: auth0.AuthOptions = {
domain: "dev-3lgt71qosvm4psf0.us.auth0.com",
clientID: "3XDxVDUz3W3038KmRvkJSjkIs5mGj7at",
redirectUri: "https://nest-auth-ts-merge.onrender.com",
// TODO: change to include offline_access, see https://github.com/Mocksi/nest/pull/10#discussion_r1635647560
responseType: "id_token token",
audience: "Mocksi Lite",
};

export const setRootPosition = (state: RecordingState | null) => {
const extensionRoot = document.getElementById("extension-root");
if (extensionRoot) {
Expand All @@ -42,13 +52,20 @@ export const setRootPosition = (state: RecordingState | null) => {
};

export const logout = () => {
// FIXME: this should redirect to a logout page first
const webAuth: WebAuth = new auth0.WebAuth(authOptions);
chrome.storage.local.clear(() => {
chrome.storage.local.set({
[MOCKSI_RECORDING_STATE]: RecordingState.UNAUTHORIZED,
});
chrome.storage.local.set(
{
[MOCKSI_RECORDING_STATE]: RecordingState.UNAUTHORIZED,
},
() =>
webAuth.logout({
clientID: authOptions.clientID,
returnTo: authOptions.redirectUri,
}),
);
});
// FIXME: this should redirect to a logout page first
window.open(SignupURL);
};

const commandsExecuted: Command[] = [];
Expand Down

0 comments on commit e285ec8

Please sign in to comment.