PWA manager is now visible to all users

This commit is contained in:
Dobromir Popov
2024-05-07 14:00:29 +03:00
parent 885f98e83e
commit c30928547c
6 changed files with 173 additions and 107 deletions

View File

@ -25,9 +25,20 @@ const Notification = async (req, res) => {
if (req.method == 'GET') {
res.statusCode = 200
res.setHeader('Allow', 'POST')
let subs = 0
if (req.query && req.query.id) {
const prisma = common.getPrismaClient();
const publisher = await prisma.publisher.findUnique({
where: { id: req.query.id },
select: { pushSubscription: true }
});
subs = Array.isArray(publisher.pushSubscription) ? publisher.pushSubscription.length : (publisher.pushSubscription ? 1 : 0);
res.end()
return
}
// send the public key in the response headers
//res.setHeader('Content-Type', 'text/plain')
res.end(process.env.NEXT_PUBLIC_WEB_PUSH_PUBLIC_KEY)
res.send({ pk: process.env.NEXT_PUBLIC_WEB_PUSH_PUBLIC_KEY, subs })
res.end()
}
if (req.method == 'PUT') {

View File

@ -64,13 +64,23 @@ export const getServerSideProps = async (context) => {
}
});
if (!item) {
const user = context.req.session.user;
const user = context.req.session?.user;
if (!user) {
return {
// redirect to '/auth/signin'. assure it is not relative path
redirect: {
destination: process.env.NEXT_PUBLIC_PUBLIC_URL + "/auth/signin",
permanent: false,
}
}
}
const message = encodeURIComponent(`Този имейл (${user?.email}) не е регистриран. Моля свържете се с администратора.`);
return {
redirect: {
destination: '/message?message=Този имейл (' + user.email + ') не е регистриран. Моля свържете се с администратора.',
destination: `/message?message=${message}`,
permanent: false,
},
}
};
}
// item.allShifts = item.assignments.map((a: Assignment[]) => a.shift);