Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete indexedDB data on logout #383

Merged
merged 1 commit into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
namespace OCA\RiotChat\AppInfo;

use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\IRequest;
use OCP\Util;

class Application extends App {
class Application extends App implements IBootstrap {
public const APP_ID = 'riotchat';

public const AvailableSettings = [
Expand All @@ -54,4 +59,15 @@ public static function AvailableLabs() {
// TODO: Remove the labs feature fully
return [];
}

public function boot(IBootContext $context): void {
$request = $this->getContainer()->get(IRequest::class);
// The user is redirected to '/login?clear=1'
if ($request->getPathInfo() === '/login') {
Util::addScript(self::APP_ID, 'logout');
}
}

public function register(IRegistrationContext $context): void {
}
}
25 changes: 25 additions & 0 deletions src/logout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* @copyright Copyright (c) 2021 Gary Kim <gary@garykim.dev>
*
* @author Gary Kim <gary@garykim.dev>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const url = new URL(window.location);
if (url.searchParams.get('clear') === "1") {
window.indexedDB.deleteDatabase('matrix-react-sdk');
window.indexedDB.deleteDatabase('matrix-js-sdk:riot-web-sync');
window.indexedDB.deleteDatabase('matrix-js-sdk:crypto');
}
7 changes: 4 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const webpack = require('webpack');
module.exports = {
entry: {
adminSettings: path.join(__dirname, 'src', 'adminSettings.js'),
main: path.join(__dirname, 'src', 'main.js'),
main: path.join(__dirname, 'src', 'main.js'),
logout: path.join(__dirname, 'src', 'logout.js'),
},
output: {
path: path.join(__dirname, 'js'),
Expand Down Expand Up @@ -37,10 +38,10 @@ module.exports = {
},
plugins: [
new VueLoaderPlugin(),
new webpack.DefinePlugin({
new webpack.DefinePlugin({
RIOT_WEB_HASH: JSON.stringify(execSync('git rev-parse HEAD', { cwd: path.resolve(__dirname, './3rdparty/riot-web') }).toString()),
RIOT_WEB_VERSION: JSON.stringify(execSync('git describe --exact-match HEAD', { cwd: path.resolve(__dirname, './3rdparty/riot-web') }).toString()),
}),
}),
],
resolve: {
extensions: ['.js', '.vue'],
Expand Down