Skip to content

Commit

Permalink
Fix window auth callback message for mobile auth flows
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed Oct 16, 2024
1 parent 3319d70 commit 0ac3ae7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/app/controllers/wallet/wallet.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import ReadWalletScript from './js/get.controller';

const router: express.Router = express.Router();

router.get('/:id', assertRequestInput(ReadWallet.validation), ReadWallet.controller);
router.get('/js/:id.:ext', assertRequestInput(ReadWalletScript.validation), ReadWalletScript.controller);
router.get('/css/:id.:ext', assertRequestInput(ReadWalletCSS.validation), ReadWalletCSS.controller);
router.get('/:id', assertRequestInput(ReadWallet.validation), ReadWallet.controller);

export default router;
2 changes: 1 addition & 1 deletion apps/api/src/app/controllers/widget/js/get.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const validation = [

const controller = async (req: Request, res: Response) => {
const pool = await PoolService.getById(req.params.id);
if (!pool) throw new NotFoundError('Pool not found.');
if (!pool) return res.end('Faulty script src provided.');

// If there are QR codes for this campaign we redirect to it's wallet equivalent
const isQRCodeCampaign = await QRCodeEntry.exists({ accountId: pool.sub });
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/views/SigninRedirect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
</div>
</template>
<script lang="ts">
import { mapStores } from 'pinia';
import { defineComponent } from 'vue';
import { supabase, useAccountStore } from '../stores/Account';
import { mapStores } from 'pinia';
export default defineComponent({
name: 'ViewSigninRedirect',
Expand Down
27 changes: 26 additions & 1 deletion apps/wallet/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,32 @@
</template>

<script lang="ts">
import { mapStores } from 'pinia';
import { defineComponent } from 'vue';
import { WALLET_URL } from './config/secrets';
import { useAccountStore, useAuthStore } from './stores';
export default defineComponent({});
export default defineComponent({
computed: {
...mapStores(useAccountStore, useAuthStore),
},
mounted() {
window.onmessage = this.onMessage;
},
methods: {
async onMessage(event: MessageEvent) {
if (!this.accountStore.settings) return;
const { domain } = this.accountStore.settings;
const localOrigin = domain && new URL(domain).origin;
const messageMap: { [message: string]: () => void } = {
'tws.auth.callback': () => this.authStore.onSignedIn(event.data.session),
};
if ([localOrigin, WALLET_URL].includes(event.origin) && messageMap[event.data.message]) {
messageMap[event.data.message]();
}
},
},
});
</script>

0 comments on commit 0ac3ae7

Please sign in to comment.