Skip to content

Commit

Permalink
fix: delete indexedDB data on logout
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Kim <gary@garykim.dev>
  • Loading branch information
gary-kim committed Jul 23, 2021
1 parent 5775f64 commit 82dd522
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
20 changes: 19 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@

namespace OCA\RiotChat\AppInfo;

use OCA\RiotChat\Listener\UserLogoutScriptListener;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\IRequest;
use OCP\User\Events\BeforeUserLoggedOutEvent;
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 +61,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

0 comments on commit 82dd522

Please sign in to comment.