You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					22 lines
				
				685 B
			
		
		
			
		
	
	
					22 lines
				
				685 B
			| 
								 
											3 years ago
										 
									 | 
							
								"use strict";
							 | 
						||
| 
								 | 
							
								Object.defineProperty(exports, "__esModule", { value: true });
							 | 
						||
| 
								 | 
							
								exports.withLogout = void 0;
							 | 
						||
| 
								 | 
							
								const getLogoutPath = (admin) => {
							 | 
						||
| 
								 | 
							
								    const { logoutPath } = admin.options;
							 | 
						||
| 
								 | 
							
								    return logoutPath.startsWith('/') ? logoutPath : `/${logoutPath}`;
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								const withLogout = (fastifyApp, admin) => {
							 | 
						||
| 
								 | 
							
								    const logoutPath = getLogoutPath(admin);
							 | 
						||
| 
								 | 
							
								    fastifyApp.get(logoutPath, async (request, reply) => {
							 | 
						||
| 
								 | 
							
								        if (request.session) {
							 | 
						||
| 
								 | 
							
								            request.session.destroy(() => {
							 | 
						||
| 
								 | 
							
								                reply.redirect(admin.options.loginPath);
							 | 
						||
| 
								 | 
							
								            });
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        else {
							 | 
						||
| 
								 | 
							
								            reply.redirect(admin.options.loginPath);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    });
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								exports.withLogout = withLogout;
							 |